提议:微信回复持久化 + 本机程序主动推送(weixin notify)/ Proposal: durable WeChat replies and local outbound notify
背景 / Background
我在自用的 fork 里给微信通道加了两个功能,已经实际跑了几天。想先问问维护者有没有兴趣合入,再决定是否拆成 PR。
I've been running two additions to the WeChat channel in my own checkout. Before splitting them into PRs I'd like to know if they fit the project's direction.
1. 回复持久化与重启恢复 / Durable replies
现状: 回复只保存在内存里。weixin serve 一旦重启,或者网络中断,还没送达的回复就丢了。
做法:
- 新增
DeliveryService,配一个 file-json 的deliveries.json仓库,按块(chunk)记录送达确认。 - 服务启动时,把还没完成的投递接着发完。
- 已经确认送达的块不会重发。
Problem: replies only live in memory, so a restart or network drop loses any reply not yet delivered.
Change: a DeliveryService backed by a file-json deliveries.json store records per-chunk acknowledgements. Unfinished deliveries resume on startup, and acknowledged chunks are never resent.
2. 本机程序主动推送 / Local outbound notify
现状: 本机程序(例如一个监控行情或 CI 的脚本)没有办法主动给用户发微信。现在只能用 /auto 定时去读一个文件,没法按事件即时触发。
做法:
- 新命令
codexbridge weixin notify --state-dir <dir> (--text … | --file …) [--scope …] [--title …]。- 只往
<state-dir>/outbox/原子写一个请求(权限 0600),不登录,也不碰 serve 锁。
- 只往
- 正在运行的
weixin serve每 2 秒扫一次 outbox,然后走与回复相同的持久投递路径:同样分块,同样重试,内容不会被当成命令执行。 - context token 过期(
ret=-2)时,请求保持 pending,不丢弃。用户下一次发消息时,先补发这些通知,再处理那条消息。 codexbridge weixin outbox查看每个请求的状态:pending、delivered 或 failed。- 每个请求最多 4000 字;没有网络监听,只有本地文件 spool。
Problem: a local program (a market or CI monitor, for example) has no way to push a WeChat message. The only route is an /auto job polling a file, which can't react to events.
Change:
- A new
weixin notifyCLI only appends an atomic request to a local spool. servesweeps the spool every 2 s and delivers through the same durable path as replies.- If the context token has expired, the request stays pending and is flushed before the user's next inbound message is handled.
weixin outboxshows the state of each request.- Each request is capped at 4000 characters. There is no network listener.
其他 / Also
- 小修复:Codex 网络重连通知期间继续等待,不提前结束 turn。
- 小修复:IP 轮换的微信请求不走环境代理。
Two small fixes: keep waiting during Codex network-reconnect notifications, and keep IP-rotated WeChat requests off the env proxy.
两个功能都有测试,并已更新 README 和 docs/usage/weixin-slash-commands.md。
Both features have tests, and the README and docs/usage/weixin-slash-commands.md are updated.
如果有兴趣,我可以按 ①持久回复 → ②notify → ③小修复 拆成几个独立的 PR。也欢迎先对设计提意见。
If you're interested, I can split this into separate PRs (durable replies → notify → small fixes). Feedback on the design first is also welcome.