wechat-clawbot 0.9.7 → 0.9.9
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 +113 -3
- package/README.zh.md +98 -3
- package/lib/bridge.d.ts +22 -0
- package/lib/bridge.d.ts.map +1 -1
- package/lib/bridge.js +91 -4
- package/lib/bridge.js.map +1 -1
- package/lib/client.js +37 -5
- package/lib/codex-peer.d.ts +70 -0
- package/lib/codex-peer.d.ts.map +1 -0
- package/lib/codex-peer.js +324 -0
- package/lib/codex-peer.js.map +1 -0
- package/lib/codex-progress.d.ts +18 -0
- package/lib/codex-progress.d.ts.map +1 -0
- package/lib/codex-progress.js +25 -0
- package/lib/codex-progress.js.map +1 -0
- package/lib/codex-rpc.d.ts +49 -0
- package/lib/codex-rpc.d.ts.map +1 -0
- package/lib/codex-rpc.js +262 -0
- package/lib/codex-rpc.js.map +1 -0
- package/lib/config.d.ts +45 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +32 -1
- package/lib/config.js.map +1 -1
- package/lib/idle-compact.d.ts +47 -0
- package/lib/idle-compact.d.ts.map +1 -0
- package/lib/idle-compact.js +129 -0
- package/lib/idle-compact.js.map +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +14 -1
- package/lib/index.js.map +1 -1
- package/lib/mcp-cli.d.ts +3 -0
- package/lib/mcp-cli.d.ts.map +1 -0
- package/lib/mcp-cli.js +29 -0
- package/lib/mcp-cli.js.map +1 -0
- package/lib/mcp-route.d.ts +4 -1
- package/lib/mcp-route.d.ts.map +1 -1
- package/lib/mcp-route.js +33 -9
- package/lib/mcp-route.js.map +1 -1
- package/lib/mcp-server.d.ts +13 -0
- package/lib/mcp-server.d.ts.map +1 -0
- package/lib/mcp-server.js +117 -0
- package/lib/mcp-server.js.map +1 -0
- package/lib/pending.d.ts +2 -0
- package/lib/pending.d.ts.map +1 -1
- package/lib/pending.js +4 -0
- package/lib/pending.js.map +1 -1
- package/lib/prompt.js +1 -1
- package/lib/workspace-instructions.d.ts +59 -0
- package/lib/workspace-instructions.d.ts.map +1 -0
- package/lib/workspace-instructions.js +67 -0
- package/lib/workspace-instructions.js.map +1 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ It uses WeChat's official **微信ClawBot** channel (Tencent iLink): no second a
|
|
|
17
17
|
- **Long-term memory**: remembers your habits and preferences, so you don't have to repeat them
|
|
18
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
19
|
- **Understands quotes**: reply to an older message with WeChat's quote feature and it knows which one you mean
|
|
20
|
+
- **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
|
|
20
21
|
|
|
21
22
|
## Requirements
|
|
22
23
|
|
|
@@ -55,7 +56,10 @@ Open **Plugins → wechat-clawbot → 微信 Bot** in the DSH web sidebar. Chang
|
|
|
55
56
|
- **Model**: pin a provider / model / reasoning effort for the bot. Leave it empty to follow DSH's global default.
|
|
56
57
|
- **Who may message the bot**: only you (the person who scanned) by default. Add WeChat user ids to let others in.
|
|
57
58
|
- **Images**: whether photos go straight to the model, and how outgoing images are resized and compressed.
|
|
58
|
-
-
|
|
59
|
+
- **空闲时整理对话** (tidy up while idle): on by default. Off leaves only DSH's own compaction, which runs right before a reply and makes that reply wait.
|
|
60
|
+
- **把工作目录的说明文件交给 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.
|
|
61
|
+
- **开放 MCP 桥(Claude / Codex)** (MCP bridge): see the integrations below.
|
|
62
|
+
- **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.
|
|
59
63
|
|
|
60
64
|
A few options (the session id, the working directory, whether to start with DSH) live in the `- id: clawbot` entry of
|
|
61
65
|
`~/.dsh/profiles/web/cordis.patch.yml`. Changing them restarts the WeChat listener automatically.
|
|
@@ -64,7 +68,7 @@ A few options (the session id, the working directory, whether to start with DSH)
|
|
|
64
68
|
|
|
65
69
|
- **Only you**: messages from anyone but the person who scanned the QR code are ignored.
|
|
66
70
|
- **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**:
|
|
71
|
+
- **Where your messages go**: to the model configured for this session in DSH. If you ask the bot to relay a message to Claude Code or Codex, it also sends that message to the selected local coding session.
|
|
68
72
|
- **Auto-memory** (on by default): short messages that look like lasting facts ("I don't drink coffee") get a second
|
|
69
73
|
question to **the same model**: should this be remembered? To turn it off, add `autoMemory: false` to the `clawbot`
|
|
70
74
|
entry in `cordis.patch.yml`. It takes effect on the next message.
|
|
@@ -95,7 +99,112 @@ A session that is already closed is resumed in the background first. This needs
|
|
|
95
99
|
|
|
96
100
|
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
101
|
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
|
|
102
|
+
need them, turn off **开放 MCP 桥(Claude / Codex)** in the 微信 Bot settings. Existing Claude MCP clients remain compatible.
|
|
103
|
+
|
|
104
|
+
## Working with Codex (optional)
|
|
105
|
+
|
|
106
|
+
The integration works in both directions:
|
|
107
|
+
|
|
108
|
+
- **WeChat → Codex**: ask the bot to list Codex projects and conversations, choose one, then relay your message.
|
|
109
|
+
DSH gets `list_codex_projects`, `list_codex_sessions`, `read_codex_session`, `send_to_codex_session`, and `read_codex_progress`.
|
|
110
|
+
Projects are grouped by the conversations' working directories. Listings are paginated; use the returned full directory
|
|
111
|
+
and conversation ID when selecting a target. Ambiguous names return candidates without sending anything.
|
|
112
|
+
- **Codex → DSH/WeChat**: the bundled `clawbot-mcp` stdio server exposes the configured DSH WeChat conversation,
|
|
113
|
+
DSH session list/read/send tools, a notification tool, and progress publishing/query tools.
|
|
114
|
+
|
|
115
|
+
### Connect Codex to the DSH WeChat session
|
|
116
|
+
|
|
117
|
+
Build this checkout and register its MCP entry point on the same machine as DSH:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm ci
|
|
121
|
+
npm run build
|
|
122
|
+
codex mcp add wechat-clawbot -- node /path/to/wechat-clawbot/lib/mcp-cli.js
|
|
123
|
+
node /path/to/wechat-clawbot/lib/mcp-cli.js --check
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Replace `/path/to/wechat-clawbot` with your checkout. For an installed version containing this integration,
|
|
127
|
+
`clawbot-mcp` is also a package executable. Reconnect the Codex client after adding the server.
|
|
128
|
+
DSH must be running with the updated plugin and **开放 MCP 桥(Claude / Codex)** enabled.
|
|
129
|
+
The default origin is `http://127.0.0.1:3080`; set `CLAWBOT_DSH_URL` if DSH uses a different port.
|
|
130
|
+
The token is read from `$CLAWBOT_STATE_DIR/mcp-token` or `$DSH_HOME/clawbot/mcp-token` (`DSH_HOME` defaults to `~/.dsh`).
|
|
131
|
+
Set `CLAWBOT_MCP_TOKEN_FILE` for another location. Pass these variables with `codex mcp add --env KEY=VALUE` as needed.
|
|
132
|
+
Keep the token in its local file, not in command arguments or repository config.
|
|
133
|
+
|
|
134
|
+
Codex can read `clawbot://wechat-session` or call `dsh_get_wechat_session` to see the WeChat session.
|
|
135
|
+
`dsh_notify_wechat({text: "…"})` sends only to the QR-linked owner and records a `[Codex 发给用户的]` copy in DSH history;
|
|
136
|
+
it does not start another bot turn. `dsh_send_to_session` drives a selected DSH conversation without automatically
|
|
137
|
+
forwarding its replies to WeChat. Use the notification tool when you want a phone update.
|
|
138
|
+
Both tools are marked as having outside effects, so with Codex's default approval settings it asks you before each call.
|
|
139
|
+
|
|
140
|
+
### Choose the Codex project and conversation from WeChat
|
|
141
|
+
|
|
142
|
+
The default `codexTransport: socket` connects to an existing shared App Server using WebSocket over a Unix socket.
|
|
143
|
+
The default socket is `$CODEX_HOME/app-server-control/app-server-control.sock` (`CODEX_HOME` defaults to `~/.codex`).
|
|
144
|
+
Set `codexSocket` to use a specific shared server's socket. Set `codexBinary` to select the CLI for standalone mode.
|
|
145
|
+
These fields belong in the `clawbot` row of
|
|
146
|
+
your local DSH `cordis.patch.yml`; changing them restarts the plugin. `codexPeer` is the switch in the settings card. It is off by default,
|
|
147
|
+
and while it is off none of these tools is sent to the model; changing it also restarts the WeChat listener.
|
|
148
|
+
|
|
149
|
+
The server must be the one executing the selected conversations and support the documented Unix socket WebSocket transport.
|
|
150
|
+
You can start a local shared service with `codex app-server --listen unix://` or `--listen unix:///path/to/rpc.sock`.
|
|
151
|
+
An already-running desktop/IDE client must expose or use that shared server for
|
|
152
|
+
live steering; **starting another daemon does not attach it to an unrelated client's running tasks**.
|
|
153
|
+
There is no silent fallback to a separate Codex runner if the shared server is unavailable.
|
|
154
|
+
|
|
155
|
+
Once connected, say, for example: "List Codex projects", "Show conversations in that project", then
|
|
156
|
+
"Send 'run the tests' to this conversation". Active turns receive `turn/steer` with the current turn ID;
|
|
157
|
+
idle conversations receive `turn/start`. Both keep the selected conversation's identity and permissions.
|
|
158
|
+
Delivery is reported immediately; completion must be checked separately.
|
|
159
|
+
An unloaded conversation requires the original client to be closed and explicit `allowResume: true`,
|
|
160
|
+
even in socket mode: another server's live execution cannot be inferred from stored history.
|
|
161
|
+
|
|
162
|
+
`notLoaded` only means this server has not loaded the conversation. Use `read_codex_session` to read its saved history.
|
|
163
|
+
Reads use summarized pages to avoid pulling large command outputs and tool results. If a response still hits the
|
|
164
|
+
8 MiB limit, reduce `limit` to 1. Reading history does not resume execution and may omit another client's unsaved messages.
|
|
165
|
+
|
|
166
|
+
A relayed message belongs to the conversation identified by the delivery result's `threadId`; it is not copied
|
|
167
|
+
into other conversations open in the app. In a regular local CLI, `/app` opens the same saved conversation in the
|
|
168
|
+
desktop app. Live execution on a shared server still requires the clients to connect to that same server.
|
|
169
|
+
You can also open a known local conversation with `codex://threads/<thread-id>`; see the
|
|
170
|
+
[desktop deep-link reference](https://learn.chatgpt.com/docs/reference/commands) and
|
|
171
|
+
[CLI command reference](https://learn.chatgpt.com/docs/developer-commands).
|
|
172
|
+
|
|
173
|
+
For background continuation of stored conversations, explicitly configure `codexTransport: stdio`.
|
|
174
|
+
That launches an independent `codex app-server --listen stdio://` using your existing Codex login/config.
|
|
175
|
+
It cannot inspect another client's live execution. A stored, unloaded conversation will only resume after you
|
|
176
|
+
close its original client and explicitly permit background continuation (`allowResume: true`).
|
|
177
|
+
No model, sandbox, or approval policy is overridden. Command/file approval requests and user questions from
|
|
178
|
+
this independent runner go to WeChat; unsupported permission grants are declined. Shared-server approvals remain
|
|
179
|
+
with the existing Codex client.
|
|
180
|
+
**stdio mode is experimental**: the approval prompts it forwards to WeChat do not yet show full details (exact
|
|
181
|
+
changes, extra permissions), and they go to whoever is chatting with the bot at the time. Use it only when you are the
|
|
182
|
+
bot's only allowed sender. The default socket mode is not affected.
|
|
183
|
+
|
|
184
|
+
### Let clawbot report progress
|
|
185
|
+
|
|
186
|
+
In Codex, ask it to call `dsh_report_codex_progress` at meaningful milestones and at the end of the task,
|
|
187
|
+
using the selected conversation's full ID:
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{"threadId":"11111111-1111-4111-8111-111111111111","state":"running","summary":"Implementing the parser"}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
States are `running`, `waiting`, `completed`, `failed`, or `interrupted`. DSH can query `read_codex_progress`,
|
|
194
|
+
and MCP clients can query `dsh_read_codex_progress`. Publishing a report does not send a phone notification;
|
|
195
|
+
Codex can separately use `dsh_notify_wechat` when requested. App Server events also populate progress for subscribed
|
|
196
|
+
conversations. `notLoaded` means live state is unknown, and a timestamped report is an observation, not a live heartbeat.
|
|
197
|
+
Progress reports are held in memory (up to 200 conversations) and cleared when the plugin restarts.
|
|
198
|
+
|
|
199
|
+
The progress HTTP routes are `POST /plugins/clawbot/mcp/codex/report` and
|
|
200
|
+
`GET /plugins/clawbot/mcp/codex/progress?threadId=…`. They use the same bearer token and live `mcpBridge` switch as
|
|
201
|
+
the existing session/notification routes. The MCP client accepts loopback origins only and refuses redirects.
|
|
202
|
+
No login data, conversation snapshots, preferences, project inventories, or local workspace indexes are bundled in the package.
|
|
203
|
+
Protocol reference: [Codex App Server](https://learn.chatgpt.com/docs/app-server).
|
|
204
|
+
|
|
205
|
+
## Contributors
|
|
206
|
+
|
|
207
|
+
- [@MistyHuang03](https://github.com/MistyHuang03): Codex integration ([#1](https://github.com/Alphainfix/wechat-clawbot/pull/1))
|
|
99
208
|
|
|
100
209
|
## Development
|
|
101
210
|
|
|
@@ -103,6 +212,7 @@ need them, turn off **开放 Claude 桥** in the 微信 Bot settings.
|
|
|
103
212
|
npm install
|
|
104
213
|
npm run build # compile to lib/
|
|
105
214
|
node test/regression.mjs # offline regression checks: no model calls, no network, no WeChat
|
|
215
|
+
npm run test:codex # synthetic Codex RPC + loopback HTTP + real MCP stdio; no model or WeChat calls
|
|
106
216
|
```
|
|
107
217
|
|
|
108
218
|
`src/ilink/` is the protocol layer ported from Tencent's MIT-licensed
|
package/README.zh.md
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
- **长期记忆**:记住你的习惯和偏好,下次不用再说一遍
|
|
18
18
|
- **先问再做**:需要你授权的操作(比如动工作目录以外的文件),会先在微信里问你,回「同意」或「拒绝」即可
|
|
19
19
|
- **看得懂引用**:引用一条旧消息回复,它知道你在说哪条
|
|
20
|
+
- **聊得越久也不变慢**:回复结束、安静一阵之后,对话太长就趁空闲把旧内容整理成摘要,你下一条消息来时不用等
|
|
20
21
|
|
|
21
22
|
## 需要什么
|
|
22
23
|
|
|
@@ -55,7 +56,10 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
55
56
|
- **模型**:给 bot 固定一个 provider / 模型 / 思考档位。留空就跟随 DSH 的全局默认模型。
|
|
56
57
|
- **允许给 bot 发消息的人**:默认只有扫码的你自己。要加人就填对方的微信用户 id。
|
|
57
58
|
- **图片**:要不要把照片直接交给模型看,以及发图时的压缩尺寸和质量。
|
|
58
|
-
-
|
|
59
|
+
- **空闲时整理对话**:默认开。关掉后只剩 DSH 在回复前压缩(会让那一条回复多等十几秒)。
|
|
60
|
+
- **把工作目录的说明文件交给 bot**:默认开(DSH 原样:bot 在哪个项目里干过活,那里的 AGENTS.md / CLAUDE.md 就会塞进对话,文件每改一次再塞一整份)。关掉则微信会话里不再自动塞,适合说明文件很长、又经常改的人;需要时让 bot 自己去读。
|
|
61
|
+
- **开放 MCP 桥(Claude / Codex)**:见下面的联动说明。
|
|
62
|
+
- **Codex 会话联动**:选择 Codex 项目和对话、转发消息、查询进度。默认关;打开后每次请求要多带 5 个工具(约 1k token),改动会重启微信监听。
|
|
59
63
|
|
|
60
64
|
少数几项(会话 id、工作目录、是否随 DSH 自动启动等)在 `~/.dsh/profiles/web/cordis.patch.yml` 的 `- id: clawbot` 里改,改完会自动重启微信监听。
|
|
61
65
|
|
|
@@ -63,7 +67,7 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
63
67
|
|
|
64
68
|
- **只有你能用**:默认只接受扫码绑定者本人的消息,陌生人的消息直接忽略。
|
|
65
69
|
- **需要授权的操作会先问你**:DSH 要你批准的操作,在微信会话里一律发到微信问你,你不回就不做。
|
|
66
|
-
-
|
|
70
|
+
- **消息去哪**:发给你为这个 DSH 会话配置的模型。你要求转发给 Claude Code 或 Codex 时,对应消息也会交给所选的本机代码会话。
|
|
67
71
|
- **自动记忆**(默认开):像「我不喝咖啡」这种看起来是长期事实的短消息,会让**同一个模型**判断要不要记下来。
|
|
68
72
|
不想要的话,在 `cordis.patch.yml` 的 `clawbot` 里加一行 `autoMemory: false`,下一条消息就生效。
|
|
69
73
|
- 绑定凭据和长期记忆都存在本机的 `~/.dsh/clawbot/` 里。
|
|
@@ -92,7 +96,97 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
92
96
|
需要本机装有 `claude` 命令行。
|
|
93
97
|
|
|
94
98
|
另外插件在本机开了一组 HTTP 接口,配合 MCP server 使用,可以让 Claude Code 反过来读写 DSH 会话、给你发一条微信通知。
|
|
95
|
-
这组接口只监听本机,并且要求令牌。不需要的话,在「微信 Bot」设置里关掉「**开放 Claude
|
|
99
|
+
这组接口只监听本机,并且要求令牌。不需要的话,在「微信 Bot」设置里关掉「**开放 MCP 桥(Claude / Codex)**」即可。已有的 Claude MCP 客户端仍然兼容。
|
|
100
|
+
|
|
101
|
+
## 和 Codex 联动(可选)
|
|
102
|
+
|
|
103
|
+
支持两个方向:
|
|
104
|
+
|
|
105
|
+
- **微信 → Codex**:让 bot 列出项目和对话,选择目标后转发消息。DSH 获得
|
|
106
|
+
`list_codex_projects`、`list_codex_sessions`、`read_codex_session`、`send_to_codex_session` 和 `read_codex_progress`。
|
|
107
|
+
项目按对话的工作目录分组,列表支持翻页。选择时使用返回的完整目录和对话 id;多个同名候选会返回选项,不会猜着发送。
|
|
108
|
+
- **Codex → DSH / 微信**:包内的 `clawbot-mcp` 是标准 stdio MCP 服务,可读取微信会话、读写 DSH 对话、给微信发通知、发布和查询 Codex 进度。
|
|
109
|
+
|
|
110
|
+
### 让 Codex 看到 DSH 微信会话和发送微信的 MCP
|
|
111
|
+
|
|
112
|
+
在运行 DSH 的同一台电脑上编译这个版本,再注册 MCP:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm ci
|
|
116
|
+
npm run build
|
|
117
|
+
codex mcp add wechat-clawbot -- node /path/to/wechat-clawbot/lib/mcp-cli.js
|
|
118
|
+
node /path/to/wechat-clawbot/lib/mcp-cli.js --check
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
把 `/path/to/wechat-clawbot` 换成实际代码目录。安装了包含此功能的包后,也可以使用 `clawbot-mcp` 可执行命令。
|
|
122
|
+
注册后重新连接 Codex 客户端。DSH 需要运行更新后的插件,并开启「开放 MCP 桥(Claude / Codex)」。
|
|
123
|
+
默认地址为 `http://127.0.0.1:3080`;端口不同可设置 `CLAWBOT_DSH_URL`。
|
|
124
|
+
令牌从 `$CLAWBOT_STATE_DIR/mcp-token` 或 `$DSH_HOME/clawbot/mcp-token` 读取,`DSH_HOME` 默认为 `~/.dsh`。
|
|
125
|
+
使用别的位置可设置 `CLAWBOT_MCP_TOKEN_FILE`。这些环境变量可通过 `codex mcp add --env KEY=VALUE` 传入。
|
|
126
|
+
令牌留在本机文件里,不要抄进命令参数或仓库配置。
|
|
127
|
+
|
|
128
|
+
Codex 可读取 `clawbot://wechat-session`,或调用 `dsh_get_wechat_session` 查看微信对话。
|
|
129
|
+
`dsh_notify_wechat({text: "…"})` 只发给扫码绑定的用户,并将带有 `[Codex 发给用户的]` 前缀的副本写入 DSH 历史,不额外触发 bot 回复。
|
|
130
|
+
`dsh_send_to_session` 可以驱动所选的 DSH 对话,其回复不会自动发到微信;需要手机通知时使用通知工具。
|
|
131
|
+
这两个工具都标注为会产生外部影响,在 Codex 默认的审批设置下,每次调用前会先征求你的同意。
|
|
132
|
+
|
|
133
|
+
### 从微信选择项目和对话来转发
|
|
134
|
+
|
|
135
|
+
默认 `codexTransport: socket` 通过 Unix socket 上的 WebSocket 连接已有的共享 App Server。
|
|
136
|
+
默认 socket 为 `$CODEX_HOME/app-server-control/app-server-control.sock`,`CODEX_HOME` 默认为 `~/.codex`。
|
|
137
|
+
连接特定共享服务时设置 `codexSocket`;为独立后台模式选择 CLI 时设置 `codexBinary`。
|
|
138
|
+
这几项写在本机 DSH `cordis.patch.yml` 的 `clawbot` 配置里,改动会重启插件。
|
|
139
|
+
「Codex 会话联动」(`codexPeer`)在设置卡片里开关,默认关;关着时这几个工具不会发给模型。改动同样会重启微信监听。
|
|
140
|
+
|
|
141
|
+
共享服务必须是实际执行目标对话的那个服务,并支持官方的 Unix socket WebSocket 传输。
|
|
142
|
+
可用 `codex app-server --listen unix://` 或 `--listen unix:///path/to/rpc.sock` 启动本机共享服务。
|
|
143
|
+
已经运行的桌面端 / IDE 客户端需要开放或使用该共享服务才能实时投递;**另开一个 daemon 不会自动接管别的客户端正在运行的任务**。
|
|
144
|
+
共享服务不可用时会明确报错,不会悄悄启动另一个 Codex 执行同一任务。
|
|
145
|
+
|
|
146
|
+
连接好后,可以在微信里说「列出 Codex 项目」「看看这个项目的对话」,选定目标后说「把运行测试这句话发给这个对话」。
|
|
147
|
+
运行中的任务通过带有当前 turn id 的 `turn/steer` 接收消息;空闲对话通过 `turn/start` 开始下一轮。
|
|
148
|
+
会话身份和权限沿用原设置。工具报告消息已投递时,工作未必已经完成,需要另查进度。
|
|
149
|
+
未加载的对话在 socket 模式下同样需要先关闭原客户端,并显式设置 `allowResume: true`;
|
|
150
|
+
历史记录不能证明别的服务里没有正在执行的任务。
|
|
151
|
+
|
|
152
|
+
`notLoaded` 只表示这个服务没有加载该会话,不妨碍用 `read_codex_session` 读取已保存的历史。
|
|
153
|
+
读取使用摘要分页,避免长任务的命令输出和工具结果撑大响应;若遇到 8 MiB 响应限制,可把 `limit` 降为 1。
|
|
154
|
+
读取历史不会恢复任务,也无法保证包含另一个客户端当前尚未保存的消息。
|
|
155
|
+
|
|
156
|
+
转发消息属于投递结果中 `threadId` 对应的对话,不会复制到 App 中当前打开的其他对话。
|
|
157
|
+
普通本机 CLI 可用 `/app` 在桌面端打开同一个已保存的对话;共享服务中的实时执行仍要求客户端连接同一服务。
|
|
158
|
+
已知本机会话 id 时,也可以用 `codex://threads/<thread-id>` 打开,参见
|
|
159
|
+
[桌面端深链接说明](https://learn.chatgpt.com/docs/reference/commands)和
|
|
160
|
+
[CLI 命令说明](https://learn.chatgpt.com/docs/developer-commands)。
|
|
161
|
+
|
|
162
|
+
如果需要对历史对话做后台续聊,显式设置 `codexTransport: stdio`。
|
|
163
|
+
它用已有的 Codex 登录和配置启动独立的 `codex app-server --listen stdio://`,无法判断另一个客户端是否仍在工作。
|
|
164
|
+
未加载的历史对话必须先关闭原客户端,并明确允许后台续聊(`allowResume: true`)才会继续执行。
|
|
165
|
+
模型、沙箱和审批策略不会被覆盖。独立服务的命令 / 文件审批和用户问题会转到微信,未支持的权限授予会被拒绝;共享服务的审批仍由原 Codex 客户端处理。
|
|
166
|
+
**stdio 模式目前是实验性的**:转到微信的审批提示还不完整(看不到具体改动和额外权限),而且会发给当时正在和 bot 聊天的人。只建议在只有你一个人能给 bot 发消息时使用;默认的 socket 模式不受影响。
|
|
167
|
+
|
|
168
|
+
### 让 clawbot 查询和汇报 Codex 进度
|
|
169
|
+
|
|
170
|
+
在 Codex 对话里要求它在重要阶段和结束时调用 `dsh_report_codex_progress`,使用已选择对话的完整 id,例如:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{"threadId":"11111111-1111-4111-8111-111111111111","state":"running","summary":"正在实现解析器"}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
状态支持 `running`、`waiting`、`completed`、`failed`、`interrupted`。
|
|
177
|
+
DSH 通过 `read_codex_progress` 查询;MCP 客户端也可通过 `dsh_read_codex_progress` 查询。
|
|
178
|
+
上报只保存进度,不自动发微信;需要通知时让 Codex 另调用 `dsh_notify_wechat`。
|
|
179
|
+
已订阅对话的 App Server 事件也会生成进度记录。`notLoaded` 表示实时状态未知;进度记录带有更新时间,不能当成持续在线的心跳。
|
|
180
|
+
记录仅存在内存里,最多保存 200 个对话,插件重启后清空。
|
|
181
|
+
|
|
182
|
+
HTTP 接口为 `POST /plugins/clawbot/mcp/codex/report` 和
|
|
183
|
+
`GET /plugins/clawbot/mcp/codex/progress?threadId=…`,和已有接口一样受 bearer token 与 `mcpBridge` 开关保护。
|
|
184
|
+
MCP 客户端只接受本机回环地址,并拒绝重定向。包里不会附带登录信息、真实对话快照、个人偏好、项目清单或本地文件索引。
|
|
185
|
+
协议说明:[Codex App Server 官方文档](https://learn.chatgpt.com/docs/app-server)。
|
|
186
|
+
|
|
187
|
+
## 贡献者
|
|
188
|
+
|
|
189
|
+
- [@MistyHuang03](https://github.com/MistyHuang03):Codex 联动([#1](https://github.com/Alphainfix/wechat-clawbot/pull/1))
|
|
96
190
|
|
|
97
191
|
## 开发
|
|
98
192
|
|
|
@@ -100,6 +194,7 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
100
194
|
npm install
|
|
101
195
|
npm run build # 编译到 lib/
|
|
102
196
|
node test/regression.mjs # 离线回归测试:不调模型、不联网、不碰微信
|
|
197
|
+
npm run test:codex # 模拟 Codex、临时回环 HTTP、真实 MCP stdio;不调模型、不发微信
|
|
103
198
|
```
|
|
104
199
|
|
|
105
200
|
`src/ilink/` 是移植自腾讯官方 MIT 许可的 [`@tencent-weixin/openclaw-weixin`](https://www.npmjs.com/package/@tencent-weixin/openclaw-weixin) 的协议层,
|
package/lib/bridge.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
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
|
+
import { type CodexPeer } from "./codex-peer.js";
|
|
4
5
|
import type { ClawbotConfig } from "./config.js";
|
|
5
6
|
import { PendingRegistry } from "./pending.js";
|
|
6
7
|
import type { ResolvedWeixinAccount } from "./ilink/auth/accounts.js";
|
|
@@ -12,6 +13,7 @@ export type BridgeDeps = {
|
|
|
12
13
|
getContextToken: (sender: string) => string;
|
|
13
14
|
/** Pending WeChat interactions (approvals + questions). */
|
|
14
15
|
pending: PendingRegistry;
|
|
16
|
+
codexPeer?: CodexPeer;
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
19
|
* The durable, serializable reference `attachments.saveImages()` hands back.
|
|
@@ -70,7 +72,27 @@ export declare class WechatBridge {
|
|
|
70
72
|
private sendChain;
|
|
71
73
|
/** 「对方正在输入…」 from the moment a WeChat message is picked up until the turn ends. */
|
|
72
74
|
private readonly typing;
|
|
75
|
+
/** Compacts the session in the quiet time after a reply (see idle-compact.ts). */
|
|
76
|
+
private readonly idleCompact;
|
|
77
|
+
/** Tokens the last model request on this session carried, as reported by the provider. */
|
|
78
|
+
private lastRequestTokens;
|
|
73
79
|
constructor(ctx: Context, config: ClawbotConfig, sendText: SendTextFn, deps: BridgeDeps);
|
|
80
|
+
/**
|
|
81
|
+
* Log once at startup whether idle compaction can work here: the host's
|
|
82
|
+
* command registry must be reachable and carry `/compact` for this session,
|
|
83
|
+
* and the route must declare a window. Without this line a missing piece
|
|
84
|
+
* would only show as "never compacts while idle".
|
|
85
|
+
*/
|
|
86
|
+
reportIdleCompactReadiness(): Promise<void>;
|
|
87
|
+
/** The host's pre-step compaction threshold for the bot's current route. */
|
|
88
|
+
private hostCompactionThreshold;
|
|
89
|
+
/**
|
|
90
|
+
* Run the host's `/compact` on the WeChat session through the command
|
|
91
|
+
* registry — the same entry the web UI's slash command uses, so the host does
|
|
92
|
+
* the compaction exactly as it would by hand. Undefined when the registry or
|
|
93
|
+
* the command is absent (e.g. a preset without compaction).
|
|
94
|
+
*/
|
|
95
|
+
private runHostCompact;
|
|
74
96
|
/** Keep 「正在输入」 up for this sender (no-op if it already is). */
|
|
75
97
|
showTyping(sender: string): void;
|
|
76
98
|
/** A message or file just reached this sender's phone. */
|
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;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAA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AgBG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAe,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAwClF,0EAA0E;YAC5D,UAAU;IAKlB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmErF,gEAAgE;IAChE,OAAO,CAAC,SAAS;IAOjB,uDAAuD;YACzC,UAAU;IAsDxB;;;;;;;;;;OAUG;IACH,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAuD3D;;;;OAIG;IACH,OAAO,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,OAAO,CAAC,WAAW;IA0BnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,aAAa;IA4CrB,6EAA6E;IACvE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB/B"}
|
package/lib/bridge.js
CHANGED
|
@@ -15,9 +15,11 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
|
15
15
|
import { zonedStamp } from "./localtime.js";
|
|
16
16
|
import { compressForUpload } from "./image-compress.js";
|
|
17
17
|
import { registerClaudePeerTools } from "./claude-peer.js";
|
|
18
|
+
import { registerCodexPeerTools } from "./codex-peer.js";
|
|
18
19
|
import { setApprovalPolicy } from "@deepseek-ai/dsh-user-approval";
|
|
19
20
|
import { markSessionCreated, wasSessionCreated } from "./state.js";
|
|
20
21
|
import { TypingIndicator } from "./typing.js";
|
|
22
|
+
import { IdleCompactor, IDLE_COMPACT_RATIO, hostCompactionThreshold } from "./idle-compact.js";
|
|
21
23
|
import { registerSendFileTool } from "./tool.js";
|
|
22
24
|
import { randomUUID } from "node:crypto";
|
|
23
25
|
import { captureTurnMemory } from "./memory-auto.js";
|
|
@@ -53,6 +55,10 @@ export class WechatBridge {
|
|
|
53
55
|
sendChain = Promise.resolve();
|
|
54
56
|
/** 「对方正在输入…」 from the moment a WeChat message is picked up until the turn ends. */
|
|
55
57
|
typing;
|
|
58
|
+
/** Compacts the session in the quiet time after a reply (see idle-compact.ts). */
|
|
59
|
+
idleCompact;
|
|
60
|
+
/** Tokens the last model request on this session carried, as reported by the provider. */
|
|
61
|
+
lastRequestTokens;
|
|
56
62
|
constructor(ctx, config, sendText, deps) {
|
|
57
63
|
this.ctx = ctx;
|
|
58
64
|
this.config = config;
|
|
@@ -64,6 +70,68 @@ export class WechatBridge {
|
|
|
64
70
|
getContextToken: (sender) => deps.getContextToken(sender),
|
|
65
71
|
isWaitingFor: (sender) => deps.pending.hasFor(sender),
|
|
66
72
|
});
|
|
73
|
+
this.idleCompact = new IdleCompactor({
|
|
74
|
+
enabled: () => this.config.idleCompaction !== false,
|
|
75
|
+
isBusy: () => this.disposed
|
|
76
|
+
|| this.worker !== null
|
|
77
|
+
|| this.queue.length > 0
|
|
78
|
+
|| deps.pending.size > 0
|
|
79
|
+
|| this.ctx.agents.get(this.sessionId)?.status === "running",
|
|
80
|
+
lastRequestTokens: () => this.lastRequestTokens,
|
|
81
|
+
hostThreshold: () => this.hostCompactionThreshold(),
|
|
82
|
+
compact: (signal) => this.runHostCompact(signal),
|
|
83
|
+
onCompacted: () => { this.lastRequestTokens = undefined; },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Log once at startup whether idle compaction can work here: the host's
|
|
88
|
+
* command registry must be reachable and carry `/compact` for this session,
|
|
89
|
+
* and the route must declare a window. Without this line a missing piece
|
|
90
|
+
* would only show as "never compacts while idle".
|
|
91
|
+
*/
|
|
92
|
+
async reportIdleCompactReadiness() {
|
|
93
|
+
if (this.config.idleCompaction === false) {
|
|
94
|
+
logger.info("idle-compact: 关闭(配置 idleCompaction: false)");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const commands = this.ctx.get?.("commands");
|
|
98
|
+
const agent = this.ctx.agents.get(this.sessionId);
|
|
99
|
+
const hasCompact = commands?.find !== undefined && agent !== undefined && commands.find(agent, "compact") !== undefined;
|
|
100
|
+
let threshold;
|
|
101
|
+
try {
|
|
102
|
+
threshold = await this.hostCompactionThreshold();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
threshold = undefined;
|
|
106
|
+
}
|
|
107
|
+
logger.info(`idle-compact: /compact ${hasCompact ? "可用" : "不可用(只剩宿主回复前的压缩)"};`
|
|
108
|
+
+ ` 宿主阈值 ${threshold ?? "未知"},空闲时超过 ${threshold === undefined ? "?" : Math.floor(threshold * IDLE_COMPACT_RATIO)} token 就整理`
|
|
109
|
+
+ `(上次请求 ${this.lastRequestTokens ?? "未知"})`);
|
|
110
|
+
}
|
|
111
|
+
/** The host's pre-step compaction threshold for the bot's current route. */
|
|
112
|
+
async hostCompactionThreshold() {
|
|
113
|
+
const route = this.currentRoute();
|
|
114
|
+
const llm = this.service("llm");
|
|
115
|
+
if (route === null || llm?.resolveModelInfo === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
const info = await llm.resolveModelInfo(route.provider, route.model);
|
|
118
|
+
return hostCompactionThreshold(info?.context?.contextWindow, info?.defaultMaxTokens);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Run the host's `/compact` on the WeChat session through the command
|
|
122
|
+
* registry — the same entry the web UI's slash command uses, so the host does
|
|
123
|
+
* the compaction exactly as it would by hand. Undefined when the registry or
|
|
124
|
+
* the command is absent (e.g. a preset without compaction).
|
|
125
|
+
*/
|
|
126
|
+
async runHostCompact(signal) {
|
|
127
|
+
const commands = this.ctx.get?.("commands");
|
|
128
|
+
const agent = this.ctx.agents.get(this.sessionId);
|
|
129
|
+
if (commands?.execute === undefined || agent === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
const out = await commands.execute(agent, "/compact", [], signal);
|
|
132
|
+
if (out === undefined)
|
|
133
|
+
return undefined;
|
|
134
|
+
return { ok: out.result.kind === "success", text: out.result.text ?? "" };
|
|
67
135
|
}
|
|
68
136
|
/** Keep 「正在输入」 up for this sender (no-op if it already is). */
|
|
69
137
|
showTyping(sender) {
|
|
@@ -642,6 +710,7 @@ export class WechatBridge {
|
|
|
642
710
|
return ref === null ? null : { type: "image", attachment: ref };
|
|
643
711
|
}
|
|
644
712
|
async enqueueMessage(sender, text, imagePath) {
|
|
713
|
+
this.idleCompact.noteActivity();
|
|
645
714
|
if (this.disposed)
|
|
646
715
|
return;
|
|
647
716
|
// Prefix every WeChat-originated message with a visible marker so the
|
|
@@ -766,9 +835,11 @@ export class WechatBridge {
|
|
|
766
835
|
catch (err) {
|
|
767
836
|
logger.error(`drainQueue: turn failed sender=${task.sender} err=${String(err)}`);
|
|
768
837
|
}
|
|
769
|
-
//
|
|
770
|
-
if (this.queue.length === 0)
|
|
838
|
+
// 后面还有排队的消息就接着显示,否则收起「正在输入」,开始等空闲压缩。
|
|
839
|
+
if (this.queue.length === 0) {
|
|
771
840
|
this.typing.stop();
|
|
841
|
+
this.idleCompact.noteIdle();
|
|
842
|
+
}
|
|
772
843
|
}
|
|
773
844
|
this.currentSender = undefined;
|
|
774
845
|
}
|
|
@@ -789,8 +860,17 @@ export class WechatBridge {
|
|
|
789
860
|
logger.debug(`sessionEvent: type=${event.type} seq=${event.seq}`);
|
|
790
861
|
// Turns the worker drives stop the indicator themselves; this covers
|
|
791
862
|
// reminder turns and messages steered into a turn someone else started.
|
|
792
|
-
if (event.type === "
|
|
863
|
+
if (event.type === "assistant/message") {
|
|
864
|
+
const tokens = event.data?.usage?.totalTokens;
|
|
865
|
+
if (typeof tokens === "number" && tokens > 0)
|
|
866
|
+
this.lastRequestTokens = tokens;
|
|
867
|
+
}
|
|
868
|
+
if (event.type === "turn/start")
|
|
869
|
+
this.idleCompact.noteActivity();
|
|
870
|
+
if (event.type === "turn/end" && !this.worker) {
|
|
793
871
|
this.typing.stop();
|
|
872
|
+
this.idleCompact.noteIdle();
|
|
873
|
+
}
|
|
794
874
|
if (event.type === "user/message" && !this.worker) {
|
|
795
875
|
// v4 drops the `plugin` field: dsh-schedule now writes `{ kind: "schedule" }`
|
|
796
876
|
// and the v3→v4 converter maps old reminders to the same. Checking only
|
|
@@ -916,9 +996,15 @@ export class WechatBridge {
|
|
|
916
996
|
// sitting in front of. restrictTools below is a DENY list, so these three
|
|
917
997
|
// are visible without needing to be named there.
|
|
918
998
|
registerClaudePeerTools(agentCtx, this.config);
|
|
999
|
+
// Codex tools only when the owner switched them on: every registered tool
|
|
1000
|
+
// rides along on every request. codexPeer is a cold field, so a flip
|
|
1001
|
+
// restarts the listener and lands here again with the new value.
|
|
1002
|
+
const codex = this.deps.codexPeer !== undefined && this.config.codexPeer === true;
|
|
1003
|
+
if (codex)
|
|
1004
|
+
registerCodexPeerTools(agentCtx, this.deps.codexPeer);
|
|
919
1005
|
this.restrictTools(agentCtx);
|
|
920
1006
|
this.toolsRegistered = true;
|
|
921
|
-
logger.info(
|
|
1007
|
+
logger.info(`ensureTools: WeChat tools registered (Codex tools ${codex ? "on" : "off"})`);
|
|
922
1008
|
}
|
|
923
1009
|
catch (err) {
|
|
924
1010
|
logger.warn(`ensureTools: registration failed (will retry): ${String(err)}`);
|
|
@@ -992,6 +1078,7 @@ export class WechatBridge {
|
|
|
992
1078
|
return;
|
|
993
1079
|
this.disposed = true;
|
|
994
1080
|
this.typing.dispose();
|
|
1081
|
+
this.idleCompact.dispose();
|
|
995
1082
|
// Dispose the agent first: this stops the driver, so a pending whenIdle
|
|
996
1083
|
// resolves and the worker can exit instead of hanging forever.
|
|
997
1084
|
try {
|