@linjz/opencode-qqbot 0.3.18 → 0.3.19
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 +1 -0
- package/README.zh-CN.md +1 -0
- package/bin/openqq.js +3 -1
- package/dist/opencode-qqbot-plugin.js +9 -4
- package/dist/openqq-watchdog.js +9 -4
- package/package.json +1 -1
- package/src/core/supervisor-election.ts +22 -7
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ Built for production, not just message bridging: a self-healing watchdog, an aud
|
|
|
38
38
|
|
|
39
39
|
### What's new in v0.3.18
|
|
40
40
|
|
|
41
|
+
- **v0.3.19 hotfix** — `bin/openqq.js` TDZ (temporal dead zone) broke every `openqq` subcommand on 0.3.16-0.3.18 with a module-eval `ReferenceError`; declaration order fixed and a bin smoke suite added to the test chain. Also fixes the supervisor lease `--once` self-deferral that diluted 5-min patrols to 10-min (channel-priority + timestamp lease, pid is diagnostics only).
|
|
41
42
|
- **`qq_send_file` first-class tool** — the AI sends local files/images to QQ via a native tool with JSON-Schema contract and precise structured errors (allowlist roots on failure); the old `QQ_SEND_FILE:` text marker survives as a fallback. No more syntax guessing.
|
|
42
43
|
- **System-level channel instructions** — QQ rendering/format rules are injected as session instructions (`<context key="qq">`), not appended to your prompt text. Session history stays clean on the desktop side.
|
|
43
44
|
- **Status cockpit** — `/status` becomes the single dashboard and the only switch entry for observation (`watch`) and digest mirror (`mirror`); standalone `/watch` `/mirror` commands retired.
|
package/README.zh-CN.md
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
### v0.3.18 新特性
|
|
37
37
|
|
|
38
|
+
- **v0.3.19 热修**:`bin/openqq.js` 的 TDZ(暂时性死区)曾致 0.3.16-0.3.18 全部 `openqq` 子命令启动即 `ReferenceError`——声明顺序已修并补 bin 冒烟套件入测试链;同批修复监督租约 `--once` 自相让贤(5min 巡检被稀释成 10min,改 channel 优先级+时间戳租约,pid 仅诊断)。
|
|
38
39
|
- **`qq_send_file` 一等工具**:AI 经原生工具发本机文件/图片到 QQ——JSON Schema 契约+结构化精确错误(白名单拒绝时直接列出可用根目录);旧 `QQ_SEND_FILE:` 文本标记保留为降级。不再猜标记。
|
|
39
40
|
- **系统级通道指令**:QQ 渲染/格式规则以会话指令注入(`<context key="qq">`),不再拼接进 prompt 正文——桌面端会话历史零污染。
|
|
40
41
|
- **驾驶舱**:`/status` 升为单点总控,观察(`watch`)与桌面摘要镜像(`mirror`)的唯一开关入口;独立 `/watch` `/mirror` 命令退役。
|
package/bin/openqq.js
CHANGED
|
@@ -11,6 +11,9 @@ import { fileURLToPath } from "node:url"
|
|
|
11
11
|
import { join, dirname } from "node:path"
|
|
12
12
|
|
|
13
13
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
14
|
+
// argv 必须先于一切分支声明(TDZ 实证 DEF-qqbot-20261125-bin:watchdog/restart/service 分支
|
|
15
|
+
// 曾在本声明之前读取 argv[0],模块求值即 ReferenceError,全部子命令失效)。
|
|
16
|
+
const argv = process.argv.slice(2)
|
|
14
17
|
|
|
15
18
|
// 2026-11-09 架构红线:看门狗/重启/自启注册都是包内 TS 产物,经本 shim 统一分发。
|
|
16
19
|
// 传参不改变无参数行为。
|
|
@@ -27,7 +30,6 @@ if (argv[0] === "restart" || argv[0] === "service") {
|
|
|
27
30
|
|
|
28
31
|
// notify 子命令分发(不改变无参数行为):CLI 只入队 ~openqq/outbox.json,
|
|
29
32
|
// 发送由 bot 进程 notify-sink 消费;CLI 不联网不取 token 不抢锁。
|
|
30
|
-
const argv = process.argv.slice(2)
|
|
31
33
|
if (argv[0] === "notify") {
|
|
32
34
|
const notifyArgs = argv.slice(1)
|
|
33
35
|
const cliDist = join(root, "dist", "notify-cli.js")
|
|
@@ -1233,21 +1233,26 @@ import { join as join8 } from "path";
|
|
|
1233
1233
|
import { homedir as homedir6 } from "os";
|
|
1234
1234
|
var LEASE_PATH = join8(homedir6(), ".openqq", "supervisor-lease.json");
|
|
1235
1235
|
var LEASE_TTL_MS = 10 * 60000;
|
|
1236
|
+
var PRIORITY = { service: 2, plugin: 1 };
|
|
1236
1237
|
function electSupervisor(channel, opts) {
|
|
1237
1238
|
const ttlMs = opts?.ttlMs ?? LEASE_TTL_MS;
|
|
1238
1239
|
const now = opts?.now ?? Date.now();
|
|
1239
1240
|
const path = opts?.path ?? LEASE_PATH;
|
|
1241
|
+
const pid = opts?.pid ?? process.pid;
|
|
1240
1242
|
try {
|
|
1241
1243
|
let cur = null;
|
|
1242
1244
|
try {
|
|
1243
1245
|
cur = JSON.parse(readFileSync9(path, "utf-8"));
|
|
1244
1246
|
} catch {}
|
|
1245
|
-
if (cur && typeof cur.until === "number" && cur.until > now) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1247
|
+
if (cur && typeof cur.until === "number" && cur.until > now && cur.channel) {
|
|
1248
|
+
if (cur.channel !== channel) {
|
|
1249
|
+
if (PRIORITY[cur.channel] > PRIORITY[channel])
|
|
1250
|
+
return false;
|
|
1251
|
+
} else if (channel === "plugin" && cur.pid !== pid) {
|
|
1248
1252
|
return false;
|
|
1253
|
+
}
|
|
1249
1254
|
}
|
|
1250
|
-
writeFileSync5(path, JSON.stringify({ channel, pid
|
|
1255
|
+
writeFileSync5(path, JSON.stringify({ channel, pid, until: now + ttlMs }));
|
|
1251
1256
|
return true;
|
|
1252
1257
|
} catch {
|
|
1253
1258
|
return true;
|
package/dist/openqq-watchdog.js
CHANGED
|
@@ -615,21 +615,26 @@ import { join as join5 } from "path";
|
|
|
615
615
|
import { homedir as homedir4 } from "os";
|
|
616
616
|
var LEASE_PATH = join5(homedir4(), ".openqq", "supervisor-lease.json");
|
|
617
617
|
var LEASE_TTL_MS = 10 * 60000;
|
|
618
|
+
var PRIORITY = { service: 2, plugin: 1 };
|
|
618
619
|
function electSupervisor(channel, opts) {
|
|
619
620
|
const ttlMs = opts?.ttlMs ?? LEASE_TTL_MS;
|
|
620
621
|
const now = opts?.now ?? Date.now();
|
|
621
622
|
const path = opts?.path ?? LEASE_PATH;
|
|
623
|
+
const pid = opts?.pid ?? process.pid;
|
|
622
624
|
try {
|
|
623
625
|
let cur = null;
|
|
624
626
|
try {
|
|
625
627
|
cur = JSON.parse(readFileSync5(path, "utf-8"));
|
|
626
628
|
} catch {}
|
|
627
|
-
if (cur && typeof cur.until === "number" && cur.until > now) {
|
|
628
|
-
|
|
629
|
-
|
|
629
|
+
if (cur && typeof cur.until === "number" && cur.until > now && cur.channel) {
|
|
630
|
+
if (cur.channel !== channel) {
|
|
631
|
+
if (PRIORITY[cur.channel] > PRIORITY[channel])
|
|
632
|
+
return false;
|
|
633
|
+
} else if (channel === "plugin" && cur.pid !== pid) {
|
|
630
634
|
return false;
|
|
635
|
+
}
|
|
631
636
|
}
|
|
632
|
-
writeFileSync3(path, JSON.stringify({ channel, pid
|
|
637
|
+
writeFileSync3(path, JSON.stringify({ channel, pid, until: now + ttlMs }));
|
|
633
638
|
return true;
|
|
634
639
|
} catch {
|
|
635
640
|
return true;
|
package/package.json
CHANGED
|
@@ -9,7 +9,15 @@
|
|
|
9
9
|
// 归一:本租约选出一个独占监督通道——赢家每 tick 续租并照常 superviseOnce,
|
|
10
10
|
// 输家整轮让贤(连 superviseOnce 都不进:不抢认领、不写强度账、零干扰);
|
|
11
11
|
// 租约过期(赢家死亡/停排,TTL 10 分钟)后另一通道自动接管,双向自愈。
|
|
12
|
-
//
|
|
12
|
+
//
|
|
13
|
+
// 2026-11-25 租约定稿(owner 令):channel 优先级 service>plugin + 时间戳判定,
|
|
14
|
+
// pid 降级为纯诊断字段——旧版按 pid 判「非我」致 --once 每轮新 pid 自相让贤
|
|
15
|
+
// (5min 计划任务实际 10min 一轮,issue 实证)。规则:
|
|
16
|
+
// ①他 channel 租约新鲜:优先级高者当值(service 恒压 plugin);低者让贤。
|
|
17
|
+
// ②同 channel:pid 相同=续租;service 下 pid 不同照常续租(--once 短进程语义);
|
|
18
|
+
// plugin 下 pid 不同且租约新鲜=让贤(多引擎并发加载互斥)。
|
|
19
|
+
// ③租约过期/缺失:本 channel 当值并覆盖写。
|
|
20
|
+
// ④service 恢复即抢回(无「后占先」态)。
|
|
13
21
|
// fail-open:租约文件不可写时放行监督——监督缺失比双触发更糟。
|
|
14
22
|
import { readFileSync, writeFileSync } from "fs"
|
|
15
23
|
import { join } from "path"
|
|
@@ -25,15 +33,17 @@ export interface SupervisorLease {
|
|
|
25
33
|
|
|
26
34
|
const LEASE_PATH = join(homedir(), ".openqq", "supervisor-lease.json")
|
|
27
35
|
const LEASE_TTL_MS = 10 * 60_000
|
|
36
|
+
const PRIORITY: Record<SupervisorChannel, number> = { service: 2, plugin: 1 }
|
|
28
37
|
|
|
29
|
-
/** 选主:持有/夺得租约返回 true
|
|
38
|
+
/** 选主:持有/夺得租约返回 true(可监督);他通道高优先级或同 plugin channel 他 pid 持新鲜租约返回 false(让贤)。 */
|
|
30
39
|
export function electSupervisor(
|
|
31
40
|
channel: SupervisorChannel,
|
|
32
|
-
opts?: { ttlMs?: number; now?: number; path?: string },
|
|
41
|
+
opts?: { ttlMs?: number; now?: number; path?: string; pid?: number },
|
|
33
42
|
): boolean {
|
|
34
43
|
const ttlMs = opts?.ttlMs ?? LEASE_TTL_MS
|
|
35
44
|
const now = opts?.now ?? Date.now()
|
|
36
45
|
const path = opts?.path ?? LEASE_PATH
|
|
46
|
+
const pid = opts?.pid ?? process.pid
|
|
37
47
|
try {
|
|
38
48
|
let cur: Partial<SupervisorLease> | null = null
|
|
39
49
|
try {
|
|
@@ -41,11 +51,16 @@ export function electSupervisor(
|
|
|
41
51
|
} catch {
|
|
42
52
|
/* 无租约或损坏 → 视为可夺 */
|
|
43
53
|
}
|
|
44
|
-
if (cur && typeof cur.until === "number" && cur.until > now) {
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
if (cur && typeof cur.until === "number" && cur.until > now && cur.channel) {
|
|
55
|
+
if (cur.channel !== channel) {
|
|
56
|
+
// 他 channel:按恒定优先级裁决——service 恒压 plugin;本端优先级低则让贤
|
|
57
|
+
if (PRIORITY[cur.channel] > PRIORITY[channel]) return false
|
|
58
|
+
} else if (channel === "plugin" && cur.pid !== pid) {
|
|
59
|
+
// 同 plugin channel 他 pid:多引擎并发加载互斥(service --once 不受此限)
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
47
62
|
}
|
|
48
|
-
writeFileSync(path, JSON.stringify({ channel, pid
|
|
63
|
+
writeFileSync(path, JSON.stringify({ channel, pid, until: now + ttlMs }))
|
|
49
64
|
return true
|
|
50
65
|
} catch {
|
|
51
66
|
return true // fail-open:租约不可写不阻断监督
|