dsh-qqbot-muu 0.1.15 → 0.1.21
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 +168 -85
- package/client/qqbot-settings.js +13401 -12024
- package/config/modules.json +212 -0
- package/dist/channel-tools.js +21 -10
- package/dist/config.d.ts +14 -0
- package/dist/config.js +573 -449
- package/dist/features/contextless-store.js +247 -247
- package/dist/features/contextless-trim.js +455 -34
- package/dist/features/four-source.js +338 -336
- package/dist/features/group-join-request.js +289 -287
- package/dist/features/local-models.js +1494 -0
- package/dist/features/rotate-summarizer.js +438 -0
- package/dist/features/scenario-detect.js +321 -0
- package/dist/features/scheduler.js +8 -1
- package/dist/features/session-rotate.js +499 -0
- package/dist/features/session-title.js +199 -0
- package/dist/features/style-layer.js +501 -0
- package/dist/features/thinking-log.js +71 -69
- package/dist/gateway/bootstrap.js +1704 -1388
- package/dist/gateway/data-root.js +77 -3
- package/dist/gateway/middleware-setup.js +6 -3
- package/dist/index.js +4 -2
- package/dist/model/settings-reader.js +193 -102
- package/dist/session/session-manager.js +1730 -1587
- package/dist/shared/paths.js +128 -0
- package/dist/shared/settings-io.js +79 -0
- package/dist/transport/inbound.js +20 -1
- package/dist/transport/outbound.js +56 -4
- package/docs/RELEASE_CHECKLIST.md +24 -2
- package/dshqqbot/.qqbot-extensions/hooks/interview-panel.mjs +41 -1
- package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
- package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -689
- package/dshqqbot/.qqbot-extensions/inbound/ac-image-see.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
- package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
- package/dshqqbot/.qqbot-extensions/lib/.pet-form.json +1 -1
- package/dshqqbot/.qqbot-extensions/lib/draw-core.mjs +238 -7
- package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -394
- package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
- package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
- package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
- package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
- package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
- package/dshqqbot/.qqbot-extensions/lib/plugin-dir.mjs +14 -4
- package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
- package/dshqqbot/.qqbot-extensions/lib/vision.mjs +1 -1
- package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
- package/dshqqbot/.qqbot-extensions/outbound/ac-media-fix.mjs +5 -1
- package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
- package/dshqqbot/.qqbot-extensions/outbound/split-reply.mjs +18 -2
- package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
- package/dshqqbot/.qqbot-extensions/tools/draw.mjs +22 -1
- package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
- package/dshqqbot/.qqbot-extensions/tools/pet_card.mjs +3 -2
- package/dshqqbot/.qqbot-extensions/tools/storyboard.mjs +3 -1
- package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
- package/package.json +119 -111
- package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
- package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
- package/scripts/_add_maintenance_cfg.py +20 -0
- package/scripts/_bench_keeplease.sh +10 -0
- package/scripts/_dbg_purge.py +15 -0
- package/scripts/_elev.sh +6 -0
- package/scripts/_fix_all_admin.cmd +16 -0
- package/scripts/_livecheck-image.mjs +33 -0
- package/scripts/_livecheck-llm.mjs +34 -0
- package/scripts/_livecheck-tts.mjs +37 -0
- package/scripts/_patch_curve.py +88 -0
- package/scripts/_patch_fan_thermal.py +24 -0
- package/scripts/_tag_tmp.py +13 -0
- package/scripts/adb-broker-client.mjs +87 -0
- package/scripts/adb-broker.mjs +205 -0
- package/scripts/ai-mode.cmd +6 -0
- package/scripts/ai-mode.py +387 -0
- package/scripts/ai-toolkit.py +607 -0
- package/scripts/apply-fan-gpu45.py +51 -0
- package/scripts/bench-fans.py +515 -0
- package/scripts/bench-load-direct.py +63 -0
- package/scripts/boot-tasks-hidden.vbs +20 -0
- package/scripts/boot-tasks.cmd +277 -0
- package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
- package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
- package/scripts/chat-archive/build-sft-v4.py +566 -0
- package/scripts/chat-archive/build-sft.py +390 -0
- package/scripts/chat-archive/eval-sft.py +155 -0
- package/scripts/chat-archive/extract-memory.py +143 -0
- package/scripts/chat-archive/inventory.py +182 -0
- package/scripts/chat-archive/merge-sft.py +114 -0
- package/scripts/chat-archive/qce-pull.py +217 -0
- package/scripts/chat-archive/qqheader.py +110 -0
- package/scripts/chat-archive/qqkey2.py +113 -0
- package/scripts/chat-archive/qqprobe.py +153 -0
- package/scripts/chat-archive/screen-collect.py +163 -0
- package/scripts/chat-archive/sqlcipher_probe.py +444 -0
- package/scripts/comfy_gen.py +209 -0
- package/scripts/compose-video.py +168 -0
- package/scripts/dl_models.py +45 -0
- package/scripts/draw-now.cmd +18 -0
- package/scripts/dsh-instance-guard.mjs +20 -2
- package/scripts/elev-extra.cmd +25 -0
- package/scripts/episode.py +529 -0
- package/scripts/fan-curve.py +218 -0
- package/scripts/fan-guard.cmd +8 -0
- package/scripts/fan-mode.py +380 -0
- package/scripts/fan_manual_safe.py +33 -0
- package/scripts/fan_restore_manual.py +46 -0
- package/scripts/fc_curves.py +359 -0
- package/scripts/fix-fan-and-timers.cmd +39 -0
- package/scripts/fix_admin_all.py +94 -0
- package/scripts/flows.mjs +224 -0
- package/scripts/gateway.cmd +126 -0
- package/scripts/gen-image.py +420 -0
- package/scripts/gen-video.py +186 -0
- package/scripts/git-askpass.cmd +2 -2
- package/scripts/gpu-mode.py +195 -0
- package/scripts/hw-profile.py +175 -0
- package/scripts/install-schedule.cmd +37 -0
- package/scripts/install-watch.cmd +29 -0
- package/scripts/matte-cutout.py +106 -0
- package/scripts/media-enhance.py +402 -0
- package/scripts/memory-audit.py +581 -0
- package/scripts/migrate-scope.mjs +140 -139
- package/scripts/model-registry.py +519 -0
- package/scripts/openid-audit.mjs +219 -0
- package/scripts/pull-gguf.py +127 -0
- package/scripts/purge-standby.py +151 -0
- package/scripts/qq-connect-login.py +133 -0
- package/scripts/qq-ip-sync-hidden.vbs +5 -0
- package/scripts/qq-ip-sync.py +300 -0
- package/scripts/qq-login-once.cmd +20 -0
- package/scripts/qq-login-qr.py +72 -0
- package/scripts/qq-whitelist-fix.cmd +27 -0
- package/scripts/qq-whitelist-login.cmd +26 -0
- package/scripts/qq-whitelist.cmd +12 -0
- package/scripts/qq-whitelist.py +1452 -0
- package/scripts/quality-compare.py +134 -0
- package/scripts/release-all.mjs +636 -430
- package/scripts/release-check.mjs +244 -226
- package/scripts/resume-coder.cmd +38 -0
- package/scripts/secure-room/index.html +334 -0
- package/scripts/secure-room/server.py +582 -0
- package/scripts/security-check.mjs +164 -0
- package/scripts/selftest-local-llm.mjs +20 -0
- package/scripts/selftest-local-models.mjs +754 -0
- package/scripts/selftest-rotate-style.mjs +308 -0
- package/scripts/shutdown-s5-optional.cmd +21 -0
- package/scripts/sleep-2325.cmd +75 -0
- package/scripts/start-comfyui.cmd +5 -0
- package/scripts/start-strata.cmd +17 -0
- package/scripts/start-strata.vbs +11 -0
- package/scripts/start-watch-hidden.vbs +3 -0
- package/scripts/stickers/auto-tag.mjs +161 -0
- package/scripts/storage.mjs +236 -0
- package/scripts/sync-plugin-copies.mjs +98 -23
- package/scripts/tests/test-qq-whitelist.py +192 -0
- package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
- package/scripts/train/gguf-quantize.py +92 -0
- package/scripts/train/gguf-to-hf.py +112 -0
- package/scripts/train/merge-lora.py +51 -0
- package/scripts/train/probe-mirrors.sh +12 -0
- package/scripts/train/probe-mirrors2.sh +20 -0
- package/scripts/train/setup-wsl.sh +23 -0
- package/scripts/train/setup-wsl2.sh +25 -0
- package/scripts/train/setup-wsl3.sh +22 -0
- package/scripts/train/setup-wsl4.sh +22 -0
- package/scripts/train/train-lora.py +319 -0
- package/scripts/vram-free.py +104 -0
- package/scripts/wechat-full-pull.mjs +1 -1
- package/settings-host.js +1047 -12
|
@@ -1,154 +1,158 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* outbound/aa-sanitize.mjs — 出站第一道闸:把不该让群友看到的东西剥掉
|
|
3
|
-
*
|
|
4
|
-
* 真机踩到的(2026-10-31 主人贴实锤):她把**整段注入回显**原样发了出来 ——
|
|
5
|
-
* 「[消息号: 11018] …好。[信条]…[/信条][状态]…[/状态][别重复]刚说过:…」
|
|
6
|
-
* 旧清单只盖了 6 种块,[信条]/[消息号]/[旧识]/[成长]/[性格观察]/[情绪回响]/[约定]/[手边]
|
|
7
|
-
* 全部漏网。v2(2026-10-31):块清单与入站 stripMemoryBlock 对齐 + 三道兜底:
|
|
8
|
-
* ① 成对块([x]…[/x])逐个剥;
|
|
9
|
-
* ② 单行块([别重复]/[手边]/[消息号: N])整行剥;
|
|
10
|
-
* ③ 截断回显兜底:剥完还残留开块标记(后面没有闭块,模型回显常被截断)→ 从标记剥到结尾。
|
|
11
|
-
* 文件名 aa- 开头 = 出站链里排最前,先洗干净再让别的扩展改写。
|
|
12
|
-
*/
|
|
13
|
-
import { createHash } from 'node:crypto';
|
|
14
|
-
import { getChatState, setChatState } from '../lib/chatlog-db.mjs';
|
|
15
|
-
|
|
16
|
-
export const name = 'sanitize-out';
|
|
17
|
-
|
|
18
|
-
// 成对块:与 inbound/aa-memory-recall.mjs stripMemoryBlock 同一清单(两处增删要同步)
|
|
19
|
-
const PAIRED = [
|
|
20
|
-
'记忆', '信条', '设定', '印象', '旧识', '性格观察', '成长',
|
|
21
|
-
'关系', '状态', 'B站', '学', '情绪回响', '约定', '听懂',
|
|
22
|
-
];
|
|
23
|
-
// 单行块:没有闭标记,一行就是一块
|
|
24
|
-
const LINE_TAGS = ['别重复', '手边'];
|
|
25
|
-
|
|
26
|
-
const PATTERNS = [
|
|
27
|
-
// ① 成对注入块
|
|
28
|
-
...PAIRED.map((t) => [new RegExp(`\\[${t}\\][\\s\\S]*?\\[/${t}\\]`, 'g'), '']),
|
|
29
|
-
// ② 单行块
|
|
30
|
-
...LINE_TAGS.map((t) => [new RegExp(`\\n?\\[${t}\\][^\\n]*`, 'g'), '']),
|
|
31
|
-
// [消息号: 11018] 头(入站 msgRef,模型有时会原样念出来)
|
|
32
|
-
[/\[消息号[^\]\n]{0,24}\]\n?/g, ''],
|
|
33
|
-
[/\[消息号(?!\])[^\n]{0,30}\n?/g, ''],
|
|
34
|
-
//
|
|
35
|
-
[/\
|
|
36
|
-
//
|
|
37
|
-
[
|
|
38
|
-
//
|
|
39
|
-
[
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (isDupCandidate) forgetLast(ctx, key);
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
1
|
+
/**
|
|
2
|
+
* outbound/aa-sanitize.mjs — 出站第一道闸:把不该让群友看到的东西剥掉
|
|
3
|
+
*
|
|
4
|
+
* 真机踩到的(2026-10-31 主人贴实锤):她把**整段注入回显**原样发了出来 ——
|
|
5
|
+
* 「[消息号: 11018] …好。[信条]…[/信条][状态]…[/状态][别重复]刚说过:…」
|
|
6
|
+
* 旧清单只盖了 6 种块,[信条]/[消息号]/[旧识]/[成长]/[性格观察]/[情绪回响]/[约定]/[手边]
|
|
7
|
+
* 全部漏网。v2(2026-10-31):块清单与入站 stripMemoryBlock 对齐 + 三道兜底:
|
|
8
|
+
* ① 成对块([x]…[/x])逐个剥;
|
|
9
|
+
* ② 单行块([别重复]/[手边]/[消息号: N])整行剥;
|
|
10
|
+
* ③ 截断回显兜底:剥完还残留开块标记(后面没有闭块,模型回显常被截断)→ 从标记剥到结尾。
|
|
11
|
+
* 文件名 aa- 开头 = 出站链里排最前,先洗干净再让别的扩展改写。
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import { getChatState, setChatState } from '../lib/chatlog-db.mjs';
|
|
15
|
+
|
|
16
|
+
export const name = 'sanitize-out';
|
|
17
|
+
|
|
18
|
+
// 成对块:与 inbound/aa-memory-recall.mjs stripMemoryBlock 同一清单(两处增删要同步)
|
|
19
|
+
const PAIRED = [
|
|
20
|
+
'记忆', '信条', '设定', '印象', '旧识', '性格观察', '成长',
|
|
21
|
+
'关系', '状态', 'B站', '学', '情绪回响', '约定', '听懂',
|
|
22
|
+
];
|
|
23
|
+
// 单行块:没有闭标记,一行就是一块
|
|
24
|
+
const LINE_TAGS = ['别重复', '手边'];
|
|
25
|
+
|
|
26
|
+
const PATTERNS = [
|
|
27
|
+
// ① 成对注入块
|
|
28
|
+
...PAIRED.map((t) => [new RegExp(`\\[${t}\\][\\s\\S]*?\\[/${t}\\]`, 'g'), '']),
|
|
29
|
+
// ② 单行块
|
|
30
|
+
...LINE_TAGS.map((t) => [new RegExp(`\\n?\\[${t}\\][^\\n]*`, 'g'), '']),
|
|
31
|
+
// [消息号: 11018] 头(入站 msgRef,模型有时会原样念出来)
|
|
32
|
+
[/\[消息号[^\]\n]{0,24}\]\n?/g, ''],
|
|
33
|
+
[/\[消息号(?!\])[^\n]{0,30}\n?/g, ''],
|
|
34
|
+
// QQ 引用标记 `[回复]`:训练语料里自带的(2026-12-04 实测模型会开口就念),纯标记,剥掉留正文
|
|
35
|
+
[/\[回复\]\s*/g, ''],
|
|
36
|
+
// 媒体占位符([图片]/[表情]…):真人不会打字打出来,模型念出来只显得像机器
|
|
37
|
+
[/\[(?:图片|视频|语音|文件|表情|动画表情|位置|音乐|表情包|卡片|转发)\]\s*/g, ''],
|
|
38
|
+
// 内部消息号:m01013b / m001f / m01013 这类(真实聊天里不会出现)
|
|
39
|
+
[/\b[mM][0-9a-fA-F]{4,8}\b/g, ''],
|
|
40
|
+
// 形如 #0913a 的裸消息号([rf:…] 里的不动,因为那是引用语法)
|
|
41
|
+
[/(^|[\s,。!?、])#([0-9a-fA-F]{5})(?=$|[\s,。!?、])/g, '$1'],
|
|
42
|
+
// ③ 截断回显兜底(必须放最后:成对块先剥完,剩下的开标记 = 没有闭块的残段)
|
|
43
|
+
[new RegExp(`\\[(?:${PAIRED.join('|')})\\][\\s\\S]*$`), ''],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
export function sanitize(text) {
|
|
47
|
+
let t = String(text == null ? '' : text);
|
|
48
|
+
for (const [re, to] of PATTERNS) t = t.replace(re, to);
|
|
49
|
+
t = t.replace(/[ \t]{2,}/g, ' ').replace(/\n{3,}/g, '\n\n').trim();
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ── 同文重复发送拦截(2026-10-31 主人反馈「容易把同一消息反复发送」)──
|
|
54
|
+
// 短窗口内(120s)与刚发出去的正文完全相同(去标点/空白归一后)→ 消灭这条,不再出站。
|
|
55
|
+
// 只拦整句重复: Length≥8 才算(「嗯」「6」这种短句自然重复不拦);主人让她「再说一遍」
|
|
56
|
+
// 时隔得久,不受影响。
|
|
57
|
+
const _lastSent = new Map(); // key: target → { norm, h, at }(内存快路径)
|
|
58
|
+
const DUP_META_PREFIX = 'dup:'; // chat_meta 键前缀(实际落盘为 state:dup:<target>)
|
|
59
|
+
function normForDup(s) {
|
|
60
|
+
return String(s || '').replace(/[\s\u3000]+/g, '').replace(/[^\u4e00-\u9fa5A-Za-z0-9]/g, '').toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
function hashOf(norm) {
|
|
63
|
+
try { return createHash('sha1').update(String(norm || '')).digest('hex').slice(0, 16); } catch { return ''; }
|
|
64
|
+
}
|
|
65
|
+
function dupKeyOf(ctx) {
|
|
66
|
+
try {
|
|
67
|
+
const t = ctx?.target;
|
|
68
|
+
if (t && typeof t === 'object') return String(t.openid || t.id || t.chatId || JSON.stringify(t));
|
|
69
|
+
} catch { /* ignore */ }
|
|
70
|
+
return String(ctx?.target ?? 'unknown');
|
|
71
|
+
}
|
|
72
|
+
function rootOf(ctx) {
|
|
73
|
+
try { return String(ctx?.dataRoot || process.env.QQBOT_MEMORY_DATA_ROOT || ''); } catch { return ''; }
|
|
74
|
+
}
|
|
75
|
+
// 读「上次发过什么」:内存优先,未命中再读 chat_meta(重启后继续生效)
|
|
76
|
+
function readLast(ctx, key) {
|
|
77
|
+
const mem = _lastSent.get(key);
|
|
78
|
+
if (mem) return mem;
|
|
79
|
+
const root = rootOf(ctx);
|
|
80
|
+
if (!root) return null;
|
|
81
|
+
try {
|
|
82
|
+
const st = getChatState(root, DUP_META_PREFIX + key);
|
|
83
|
+
const at = Number(st?.at);
|
|
84
|
+
const h = String(st?.h || '');
|
|
85
|
+
if (!h || !Number.isFinite(at) || at <= 0) return null;
|
|
86
|
+
return { norm: '', h, at };
|
|
87
|
+
} catch { return null; }
|
|
88
|
+
}
|
|
89
|
+
// 「发送失败」:删掉内存账并把持久化写空(chatlog-db 没有删除 API)
|
|
90
|
+
function forgetLast(ctx, key) {
|
|
91
|
+
try { _lastSent.delete(key); } catch { /* ignore */ }
|
|
92
|
+
const root = rootOf(ctx);
|
|
93
|
+
if (!root) return;
|
|
94
|
+
try { setChatState(root, DUP_META_PREFIX + key, { h: '', at: 0 }); } catch { /* ignore */ }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function onOutbound(ctx, next) {
|
|
98
|
+
if (!ctx || ctx.phase !== 'send' || ctx.kind !== 'text') return next();
|
|
99
|
+
const before = String(ctx.text || '');
|
|
100
|
+
if (!before) return next();
|
|
101
|
+
let after = sanitize(before);
|
|
102
|
+
if (!after) after = '……';
|
|
103
|
+
|
|
104
|
+
const key = dupKeyOf(ctx);
|
|
105
|
+
const norm = normForDup(after);
|
|
106
|
+
const isDupCandidate = Boolean(norm && norm.length >= 8);
|
|
107
|
+
|
|
108
|
+
// 同文重复拦截(剥完块再比,免得被剥掉的前后缀造成假差异)
|
|
109
|
+
try {
|
|
110
|
+
if (isDupCandidate) {
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
const last = readLast(ctx, key);
|
|
113
|
+
const same = Boolean(last && (last.norm ? last.norm === norm : last.h === hashOf(norm)));
|
|
114
|
+
if (same && now - last.at < 120_000) {
|
|
115
|
+
try { ctx.logger?.warn?.(`[sanitize] 同文重复发送已拦截(${Math.round((now - last.at) / 1000)}s 前发过同一句)`); } catch {}
|
|
116
|
+
try { ctx.note && ctx.note('sanitize: 拦截同文重复'); } catch {}
|
|
117
|
+
ctx.annihilate?.('重复发送拦截');
|
|
118
|
+
return; // 已被消灭,链不必再走
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch { /* 判重失败不拦正常发送 */ }
|
|
122
|
+
|
|
123
|
+
if (after !== before) {
|
|
124
|
+
try {
|
|
125
|
+
ctx.note && ctx.note('sanitize: 剥掉了内部标记');
|
|
126
|
+
} catch {}
|
|
127
|
+
try {
|
|
128
|
+
ctx.rewrite(after);
|
|
129
|
+
} catch {}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 2026-11-08(P1-5):记账挪到 next() 之后 —— 下游失败时不留"已发过"的假账。
|
|
133
|
+
// 边界:出站链是「发送前改写链」,真正网络发送由 transport 在链后执行,
|
|
134
|
+
// 本闸只能观测「链内抛错 / 明确返回 false」,观察不到 transport 的发送结果。
|
|
135
|
+
let ret;
|
|
136
|
+
try {
|
|
137
|
+
ret = await next();
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (isDupCandidate) forgetLast(ctx, key); // 失败删除该键,允许立刻重试同句
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
if (ret === false) {
|
|
143
|
+
if (isDupCandidate) forgetLast(ctx, key);
|
|
144
|
+
return ret;
|
|
145
|
+
}
|
|
146
|
+
// 记录「已发出去的正文」供下一条判重(内存 + chat_meta:target + hash + 时间,不落正文)
|
|
147
|
+
try {
|
|
148
|
+
if (isDupCandidate) {
|
|
149
|
+
const at = Date.now();
|
|
150
|
+
_lastSent.set(key, { norm, h: hashOf(norm), at });
|
|
151
|
+
const root = rootOf(ctx);
|
|
152
|
+
if (root) setChatState(root, DUP_META_PREFIX + key, { h: hashOf(norm), at });
|
|
153
|
+
}
|
|
154
|
+
} catch { /* 记账失败不影响发送 */ }
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export default onOutbound;
|
|
@@ -35,7 +35,11 @@ function dataRootOf(ctx) {
|
|
|
35
35
|
const BARE_MEDIA = /(?<!\[)\bMEDIA:(image|record|video|file)\|([^\]\s]+)/gi;
|
|
36
36
|
const DOUBLE = /\[\[(MEDIA:[^\]]+)\]\]/gi;
|
|
37
37
|
const BARE_FILE = /(?<![\w./\\-])([0-9a-fA-F]{8,16})\.(jpe?g|png|gif|webp)(?![\w./\\-])/g;
|
|
38
|
-
|
|
38
|
+
// 2026-12-02 主人报「回复里直接露出 [STICKER:无语]」:旧正则只认 ASCII id
|
|
39
|
+
// ([0-9a-zA-Z_.-]),模型写成中文标签时整段匹配不上 → 既不换图也不删除,
|
|
40
|
+
// 标记原样发给对方。这里放宽成「方括号里任意非 ] 字符」,交给 resolveToken
|
|
41
|
+
// 按 id / hash 前缀 / 标签描述去查;查不到再删标记。
|
|
42
|
+
const STICKER_TAG = /\[(?:STICKER|表情)\s*[::]\s*([^\]\n]{1,40})\]/gi;
|
|
39
43
|
|
|
40
44
|
function log(root, rec) {
|
|
41
45
|
try {
|
|
@@ -1,130 +1,121 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* outbound/memory-agent.mjs — 回合收尾时唤一次「记忆分身」
|
|
3
|
-
*
|
|
4
|
-
* 为什么放在 outbound/turnEnd:
|
|
5
|
-
* · 此时她刚说完,最近对话最完整(含她自己的回复);
|
|
6
|
-
* · 正文块已经发完,不会挡用户看到回复;
|
|
7
|
-
* · 和 turn-memory 一样只在 turnEnd 触发,天然一回合一次。
|
|
8
|
-
*
|
|
9
|
-
* 行为:
|
|
10
|
-
* 1) 同步补一次聊天台账(新增行才写,成本 ≈ 读几个 KB);
|
|
11
|
-
* 2) 把「整理这段对话」丢给 lib/memory-agent.mjs,**不 await**;
|
|
12
|
-
* 3) 同一 scope 正在整理时直接跳过,避免堆积并发小模型请求。
|
|
13
|
-
*
|
|
14
|
-
* 关闭方式:memory-config.json → "memoryAgent": { "enabled": false }
|
|
15
|
-
* 或整个记忆关掉("enabled": false)。任何异常都静默降级。
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { dirname } from 'node:path';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* ·
|
|
35
|
-
* ·
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
* ·
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})
|
|
123
|
-
.catch(() => { /* 整理失败不影响任何链路 */ })
|
|
124
|
-
.finally(() => { _running.delete(scope); });
|
|
125
|
-
} catch { /* ignore */ }
|
|
126
|
-
|
|
127
|
-
return next();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export default onOutbound;
|
|
1
|
+
/**
|
|
2
|
+
* outbound/memory-agent.mjs — 回合收尾时唤一次「记忆分身」
|
|
3
|
+
*
|
|
4
|
+
* 为什么放在 outbound/turnEnd:
|
|
5
|
+
* · 此时她刚说完,最近对话最完整(含她自己的回复);
|
|
6
|
+
* · 正文块已经发完,不会挡用户看到回复;
|
|
7
|
+
* · 和 turn-memory 一样只在 turnEnd 触发,天然一回合一次。
|
|
8
|
+
*
|
|
9
|
+
* 行为:
|
|
10
|
+
* 1) 同步补一次聊天台账(新增行才写,成本 ≈ 读几个 KB);
|
|
11
|
+
* 2) 把「整理这段对话」丢给 lib/memory-agent.mjs,**不 await**;
|
|
12
|
+
* 3) 同一 scope 正在整理时直接跳过,避免堆积并发小模型请求。
|
|
13
|
+
*
|
|
14
|
+
* 关闭方式:memory-config.json → "memoryAgent": { "enabled": false }
|
|
15
|
+
* 或整个记忆关掉("enabled": false)。任何异常都静默降级。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { dirname } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { scopeOfTarget } from '../lib/scope-util.mjs';
|
|
21
|
+
|
|
22
|
+
export const name = 'memory-agent';
|
|
23
|
+
|
|
24
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const _running = new Set();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 历史印象(高维卡)的自动更新。
|
|
29
|
+
*
|
|
30
|
+
* 之前这套只有面板里手动点才会跑,配置里 `digest.perDayMs`("每天最多重建一次")
|
|
31
|
+
* 等于一句空话——导入再多历史,那张"这个人是谁"的卡也不会自己长出来。
|
|
32
|
+
*
|
|
33
|
+
* 三处限流,任何一处不满足就不跑:
|
|
34
|
+
* · 只做 c2c:群里的卡要按发言人做,出站钩子拿不到稳定的发言人 id;
|
|
35
|
+
* · 进程内 12h/人:模型离线反复失败时不至于每回合撞一次 60s 超时;
|
|
36
|
+
* · digestPerson 内部的 perDayMs:跨进程重启也不会重复重建。
|
|
37
|
+
*/
|
|
38
|
+
const DIGEST_EVERY_MS = 12 * 3600 * 1000;
|
|
39
|
+
const _lastDigest = new Map();
|
|
40
|
+
|
|
41
|
+
async function maybeDigest(root, scope, cfg, ok) {
|
|
42
|
+
if (!ok) return null;
|
|
43
|
+
if (cfg?.digest?.auto === false) return null;
|
|
44
|
+
if (!scope.startsWith('c2c:')) return null;
|
|
45
|
+
const sid = scope.slice(4);
|
|
46
|
+
if (!sid) return null;
|
|
47
|
+
const k = root + '|' + sid;
|
|
48
|
+
if (Date.now() - (Number(_lastDigest.get(k)) || 0) < DIGEST_EVERY_MS) return null;
|
|
49
|
+
_lastDigest.set(k, Date.now());
|
|
50
|
+
const { digestPerson } = await import('../lib/profile-digest.mjs');
|
|
51
|
+
return digestPerson({ dataRoot: root, senderId: sid, scope: '', cfg });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 印象「保鲜」(主人 2026-10-27):
|
|
56
|
+
* · 卡片长期不更新,面板上的印象就会和目标偏移;
|
|
57
|
+
* · 自我卡("我自己是谁")以前是每次面板临时合成的,库里那张停在 10-26,从不变。
|
|
58
|
+
* 所以每 N 小时做一次轻量保养:
|
|
59
|
+
* 1) 重写自我卡(纯读 character.json + growth,不花 token);
|
|
60
|
+
* 2) 挑最多 1 个"有新切片没消化 / 太旧"的人重建卡(digestPerson 自带 22h 节流)。
|
|
61
|
+
* 进程内 6h 一次;异常静默。
|
|
62
|
+
*/
|
|
63
|
+
const FRESH_EVERY_MS = 6 * 3600 * 1000;
|
|
64
|
+
const _lastFresh = new Map();
|
|
65
|
+
|
|
66
|
+
async function maybeFresh(root, cfg) {
|
|
67
|
+
if (cfg?.personaFresh?.enabled === false) return null;
|
|
68
|
+
const k = root;
|
|
69
|
+
if (Date.now() - (Number(_lastFresh.get(k)) || 0) < FRESH_EVERY_MS) return null;
|
|
70
|
+
_lastFresh.set(k, Date.now());
|
|
71
|
+
const { refresh } = await import('../lib/persona-fresh.mjs');
|
|
72
|
+
return refresh(root, { mode: 'stale', budget: 1, force: false, cfg });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function dataRootOf(ctx) {
|
|
76
|
+
const env = String(process.env.QQBOT_MEMORY_DATA_ROOT || '').trim();
|
|
77
|
+
if (env) return env;
|
|
78
|
+
if (ctx && typeof ctx.dataRoot === 'string' && ctx.dataRoot) return ctx.dataRoot;
|
|
79
|
+
return dirname(dirname(HERE)); // .../{dataRoot}/.qqbot-extensions/outbound/
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function onOutbound(ctx, next) {
|
|
83
|
+
if (ctx?.phase !== 'turnEnd') return next();
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const root = dataRootOf(ctx);
|
|
87
|
+
const scope = scopeOfTarget(ctx?.target);
|
|
88
|
+
if (!scope || _running.has(scope)) return next();
|
|
89
|
+
|
|
90
|
+
const mem = await import('../lib/memory.mjs');
|
|
91
|
+
const cfg = mem.loadConfig(root);
|
|
92
|
+
if (cfg.enabled === false) return next();
|
|
93
|
+
|
|
94
|
+
const { runTurnAgent, loadAgentCfg } = await import('../lib/memory-agent.mjs');
|
|
95
|
+
const acfg = loadAgentCfg(cfg);
|
|
96
|
+
if (acfg.enabled === false) return next();
|
|
97
|
+
|
|
98
|
+
_running.add(scope);
|
|
99
|
+
// 故意不 await:整理要调本地模型(几百 ms ~ 几秒),不能拖慢收尾
|
|
100
|
+
Promise.resolve()
|
|
101
|
+
.then(async () => {
|
|
102
|
+
let llmCfg = null;
|
|
103
|
+
try {
|
|
104
|
+
const llm = await import('../lib/local-llm.mjs');
|
|
105
|
+
llmCfg = llm.loadConfig(root);
|
|
106
|
+
} catch { /* 没有本地模型就交给 runTurnAgent 自己判 */ }
|
|
107
|
+
const r = await runTurnAgent({ dataRoot: root, scope, cfg, llmCfg, reply: String(ctx?.text || '') });
|
|
108
|
+
// 回合整理成功 = 这段对话真的在推进,顺手看一眼"这个人的历史印象"要不要重建。
|
|
109
|
+
// 慢(本地模型几十秒),所以继续往后扔,不阻塞收尾。
|
|
110
|
+
maybeDigest(root, scope, cfg, !!(r && r.ok)).catch(() => { /* 卡片没更新不影响聊天 */ });
|
|
111
|
+
maybeFresh(root, cfg).catch(() => { /* 保鲜失败不影响聊天 */ });
|
|
112
|
+
return r;
|
|
113
|
+
})
|
|
114
|
+
.catch(() => { /* 整理失败不影响任何链路 */ })
|
|
115
|
+
.finally(() => { _running.delete(scope); });
|
|
116
|
+
} catch { /* ignore */ }
|
|
117
|
+
|
|
118
|
+
return next();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default onOutbound;
|
|
@@ -100,8 +100,19 @@ const ENDS = '。!?!?…~~';
|
|
|
100
100
|
|
|
101
101
|
/** 切成气泡(保留标点) */
|
|
102
102
|
export function splitBubbles(text, max = 3) {
|
|
103
|
-
const
|
|
103
|
+
const raw = String(text || '').replace(/\r/g, '').trim();
|
|
104
|
+
if (!raw) return [];
|
|
105
|
+
// 2026-12-01 主人反馈「语句段落划分有问题」:
|
|
106
|
+
// 旧实现一上来就把换行 `/\\s+/` 压成空格,再按句号硬切,最后 `slice(0, max)` ——
|
|
107
|
+
// ① 多段排版的回复被拍平成一坨;② 超过 max 条的**后半段直接丢掉**(真的会少半句话)。
|
|
108
|
+
// 所以这里先做「该不该拆」的判定:只要模型用了换行/列表/代码块,就说明它有意分段,
|
|
109
|
+
// 一律原样一条发出,绝不按标点肢解。
|
|
110
|
+
if (/\n/.test(raw)) return [raw];
|
|
111
|
+
if (/```|`[^`\n]+`/.test(raw)) return [raw];
|
|
112
|
+
if (/^\s*(?:[-*+]\s|\d+[.)]\s|>\s)/m.test(raw)) return [raw];
|
|
113
|
+
const t = raw.replace(/[ \t]+/g, ' ').trim();
|
|
104
114
|
if (!t) return [];
|
|
115
|
+
|
|
105
116
|
const parts = [];
|
|
106
117
|
let cur = '';
|
|
107
118
|
for (const ch of t) {
|
|
@@ -127,7 +138,12 @@ export function splitBubbles(text, max = 3) {
|
|
|
127
138
|
merged[merged.length - 1] += t2;
|
|
128
139
|
} else merged.push(t2);
|
|
129
140
|
}
|
|
130
|
-
|
|
141
|
+
const cap = Math.max(1, max);
|
|
142
|
+
if (merged.length <= cap) return merged;
|
|
143
|
+
// 收口:超出上限的**全部并进最后一条**,一个字都不丢(旧版 slice 会静默截断)
|
|
144
|
+
const head = merged.slice(0, cap - 1);
|
|
145
|
+
head.push(merged.slice(cap - 1).join(''));
|
|
146
|
+
return head;
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|