@pi-flash-plugins/pf-wxbot 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-flash-plugins/pf-wxbot",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "engines": {
5
5
  "pf": ">=0.3.2"
6
6
  },
package/pf-plugin.toml CHANGED
@@ -2,7 +2,7 @@
2
2
  schema = 5
3
3
  id = "pf-wxbot"
4
4
  title = { zh = "微信通信", en = "PF-WeChat" }
5
- version = "0.1.3"
5
+ version = "0.1.4"
6
6
 
7
7
  wasm = "plugin.wasm"
8
8
 
package/pi/index.mjs CHANGED
@@ -45,6 +45,16 @@ export function resolve_session_file(ownFile, ownerKey) {
45
45
  return ownFile ?? ownerKey ?? null;
46
46
  }
47
47
 
48
+ /** 从进程 argv 解析 `--session <file>`(pi spawn 必带,恢复/新会话皆是)。
49
+ * 第三把身份钥匙:恢复会话的进程里 getSessionFile() 首条消息前是
50
+ * undefined、uuid 又随重启漂移——门控两把旧钥匙同时落空,服务不起、
51
+ * 微信消息无人收(真机 2026-11-03:修复停用重启后必然踩中)。 */
52
+ export function session_file_from_argv(argv = process.argv) {
53
+ const i = argv.findIndex((a) => a === "--session");
54
+ const v = i >= 0 ? argv[i + 1] : undefined;
55
+ return typeof v === "string" && v !== "" ? v : null;
56
+ }
57
+
48
58
  /** 本进程出生时刻(模块加载即定格,早于 session_start 数百毫秒)。卸载
49
59
  * 水位线:壳写的 unload_ts > BOOT_TS = 本进程服役期内被停用。与盘上快照
50
60
  * 无关,免疫「快照晚于壳写」竞态与整文件回写弄脏序号两类坑。
@@ -582,7 +592,7 @@ export function create_entry(deps = {}) {
582
592
  } catch {
583
593
  return null;
584
594
  }
585
- })();
595
+ })() ?? (deps.argv ? session_file_from_argv(deps.argv) : session_file_from_argv());
586
596
  line.key = ownKey;
587
597
  line.name = sessionCtx?.sessionManager?.getSessionName?.() ?? ownKey;
588
598
  snap.refresh(true);
package/pi/index.test.mjs CHANGED
@@ -5,7 +5,7 @@
5
5
  import { test } from "node:test";
6
6
  import assert from "node:assert/strict";
7
7
 
8
- import { create_entry, resolve_session_file } from "./index.mjs";
8
+ import { create_entry, resolve_session_file, session_file_from_argv } from "./index.mjs";
9
9
  import { WX_LINK_ON, WX_LINK_OFF } from "./hook.mjs";
10
10
 
11
11
  // ---------------------------------------------------------------- 假件
@@ -537,6 +537,17 @@ test("resolve_session_file —— pi 首条消息前 getSessionFile 未就绪时
537
537
  assert.equal(resolve_session_file(null, null), null);
538
538
  });
539
539
 
540
+ test("session_file_from_argv —— 恢复会话进程的第三把身份钥匙", () => {
541
+ // 真机 2026-11-03:停用→启用真重启 pi 后,恢复会话的进程里 getSessionFile()
542
+ // 首条消息前 undefined + uuid 漂移,门控两把旧钥匙同时落空 → 服务不起、
543
+ // 消息无人收。pi spawn 必带 --session <file>,argv 兜底解析。
544
+ const argv = ["node", "cli.js", "--mode", "rpc", "--session", "C:\\s\\a.jsonl", "-ne"];
545
+ assert.equal(session_file_from_argv(argv), "C:\\s\\a.jsonl");
546
+ assert.equal(session_file_from_argv(["node", "x.js"]), null, "无 --session = null");
547
+ assert.equal(session_file_from_argv(["node", "x.js", "--session"]), null, "缺值 = null");
548
+ assert.equal(session_file_from_argv(["node", "x.js", "--session", ""]), null, "空值 = null");
549
+ });
550
+
540
551
  test("switch 关再开必须能恢复通信(Stopped 终态 → 回 Pending)", async () => {
541
552
  // 真机 2026-10-28:off 走 stop_service(true) = Stopped,wants_start 恒 false,
542
553
  // 打开回来后渠道永远不起 → 消息不回。这里盯状态机的可达性。