pi-wechat-gateway 0.2.0 → 0.3.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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 — 2026-12-05
4
+
5
+ - **slug 口径与 pi-auto 统一**:`src/slug.ts` 从 `path.basename()` 改为「相对 $HOME 的路径,
6
+ 非 `[A-Za-z0-9_-]` 压成 `-`」(与 pi-auto `extensions/pi-auto.ts:slugFor` 同一份算法)。
7
+ 影响:`$HOME` 下第一层目录的 slug 不变(`~/y700-elden` → `y700-elden`),
8
+ 多层/`$HOME` 外的目录从「只取最后一段」变成完整相对路径(`/tmp/a/b`:`b` → `tmp-a-b`)。
9
+ 为什么要改:pi-auto 用这个 slug 命名 tmux 会话与 `retired/<slug>.json`,用户看到的也是它;
10
+ 两边不一致会让网关把消息投到错的会话(或找不到会话)。
11
+ - 跨包对拍测试重写:直接 import pi-auto 的实现逐字比对,拿不到时**显式 skip**。
12
+ 此前对拍对象是已退役的 `boot-agents/extensions/nightly.ts`,`import` 失败被 `catch {}` 吞掉
13
+ ⇒ 测试名写着「同口径」但从未真正比对(2026-12-05 插件质量审计)。
14
+ - 测试夹具改用 `$HOME` 下目录(slug 语义如此),45 条全绿。
15
+
16
+ ## 0.2.1
17
+
18
+ - 换绑/多账号:游标归属判定、`credentials clear` 墓碑、换 bot 后丢弃旧 context token。
19
+
20
+ ## 0.2.0
21
+
22
+ - 一条微信通道多会话:引用 `>[slug]` > `@slug` > 最近提问 > hub 路由;出站 outbox(节流/免打扰/
23
+ 失败重试)、入站 pi-mailbox 投递(前缀 `【微信】`、积压自报年龄、`expiresAt`);单实例 systemd 服务。
package/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  **一条微信通道,多个 Pi 会话。** 出站:任何会话往 outbox 落一个 JSON;入站:网关路由后投进该会话的
4
4
  `pi-mailbox` 信箱(`sendUserMessage`,真正进上下文)。会话不再各自持有微信桥,也就不再有「单桥单会话」的锁。
5
5
 
6
+ ![cli](docs/demo.png)
7
+
8
+ *实机截图:`pi-wechat-gateway` 的子命令(登录/发消息/路由/服务管理都在这一个入口)。*
9
+
6
10
  协议层取腾讯官方 `@tencent-weixin/openclaw-weixin`(MIT)的**纯协议模块**,不复用它的 OpenClaw 宿主层:
7
11
 
8
12
  | 用到的 | 不用(绑 OpenClaw) |
package/package.json CHANGED
@@ -1,44 +1,45 @@
1
1
  {
2
- "name": "pi-wechat-gateway",
3
- "version": "0.2.0",
4
- "description": "One WeChat channel, many Pi sessions: an out-of-process iLink gateway that fans notifications in, routes replies back by quote/prefix, and keeps every session free of the single-bridge lock.",
5
- "keywords": [
6
- "pi",
7
- "wechat",
8
- "ilink",
9
- "gateway",
10
- "notifications"
11
- ],
12
- "type": "module",
13
- "license": "MIT",
14
- "author": "Qianhui Xu",
15
- "engines": {
16
- "node": ">=22.19.0"
17
- },
18
- "bin": {
19
- "pi-wechat-gateway": "./src/main.ts"
20
- },
21
- "files": [
22
- "src",
23
- "systemd",
24
- "README.md",
25
- "LICENSE"
26
- ],
27
- "scripts": {
28
- "test": "node --test 'test/*.test.mjs'",
29
- "check": "node --check src/main.ts 2>/dev/null || node --input-type=module -e \"await import('./src/router.ts'); await import('./src/queue.ts'); console.log('ok')\"",
30
- "validate": "npm run test && npm run check"
31
- },
32
- "dependencies": {
33
- "@tencent-weixin/openclaw-weixin": "^2.4.10",
34
- "qrcode-terminal": "0.12.0"
35
- },
36
- "repository": {
37
- "type": "git",
38
- "url": "git+ssh://git@github.com/xiaquwan1001/pi-wechat-gateway.git"
39
- },
40
- "homepage": "https://github.com/xiaquwan1001/pi-wechat-gateway#readme",
41
- "bugs": {
42
- "url": "https://github.com/xiaquwan1001/pi-wechat-gateway/issues"
43
- }
2
+ "name": "pi-wechat-gateway",
3
+ "version": "0.3.0",
4
+ "description": "One WeChat channel, many Pi sessions: an out-of-process iLink gateway that fans notifications in, routes replies back by quote/prefix, and keeps every session free of the single-bridge lock.",
5
+ "keywords": [
6
+ "pi",
7
+ "wechat",
8
+ "ilink",
9
+ "gateway",
10
+ "notifications"
11
+ ],
12
+ "type": "module",
13
+ "license": "MIT",
14
+ "author": "Qianhui Xu",
15
+ "engines": {
16
+ "node": ">=22.19.0"
17
+ },
18
+ "bin": {
19
+ "pi-wechat-gateway": "src/main.ts"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "systemd",
24
+ "README.md",
25
+ "CHANGELOG.md",
26
+ "LICENSE"
27
+ ],
28
+ "scripts": {
29
+ "test": "node --test 'test/*.test.mjs'",
30
+ "check": "node --check src/main.ts 2>/dev/null || node --input-type=module -e \"await import('./src/router.ts'); await import('./src/queue.ts'); console.log('ok')\"",
31
+ "validate": "npm run test && npm run check"
32
+ },
33
+ "dependencies": {
34
+ "@tencent-weixin/openclaw-weixin": "^2.4.10",
35
+ "qrcode-terminal": "0.12.0"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+ssh://git@github.com/xiaquwan1001/pi-wechat-gateway.git"
40
+ },
41
+ "homepage": "https://github.com/xiaquwan1001/pi-wechat-gateway#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/xiaquwan1001/pi-wechat-gateway/issues"
44
+ }
44
45
  }
package/src/slug.ts CHANGED
@@ -1,11 +1,18 @@
1
- // 与 pi-nightly 的 slugFor 同一口径(跨包契约:两侧输出必须逐字一致,由 test/slug.test.mjs 对拍)。
1
+ // slug 口径与 pi-auto(extensions/pi-auto.ts:slugFor)同一份算法:
2
+ // 会话目录 →「相对 $HOME 的路径,非 [A-Za-z0-9_-] 一律压成 -」,$HOME 本身是 "home"。
3
+ // 为什么必须同源:pi-auto 用它命名 tmux 会话与 retired/<slug>.json,用户看到的 slug 也来自它;
4
+ // 网关用它把 presence.cwd 映射回 slug,才能把微信消息投到正确的在线会话。
5
+ // 2026-12-05 审计:此前这里是 path.basename() 版本(多层目录与 pi-auto 不一致),且对拍测试
6
+ // 指向已退役的 boot-agents/extensions/nightly.ts、import 失败被 catch 吞掉 ⇒ 契约从未真正校验。
7
+ // 现在由 test/router.test.mjs 直接 import pi-auto 的实现逐字对拍(拿不到就显式 skip,不假装通过)。
2
8
  import os from "node:os";
3
9
  import path from "node:path";
4
10
 
5
11
  export function slugFor(cwd: string): string {
6
- const home = os.homedir();
7
- if (path.resolve(cwd) === path.resolve(home)) return "home";
8
- const base = path.basename(path.resolve(cwd)) || "root";
9
- const clean = base.replace(/[^\w.@-]+/g, "-").replace(/^-+|-+$/g, "");
12
+ const home = path.resolve(os.homedir());
13
+ const abs = path.resolve(cwd);
14
+ if (abs === home) return "home";
15
+ const rel = abs.startsWith(`${home}${path.sep}`) ? abs.slice(home.length + 1) : abs.replace(/^\/+/, "");
16
+ const clean = rel.replace(/[^A-Za-z0-9_-]+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
10
17
  return clean || "root";
11
18
  }