dsh-qqbot-muu 0.1.20 → 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.
Files changed (92) hide show
  1. package/CHANGELOG.md +168 -154
  2. package/client/qqbot-settings.js +13401 -13380
  3. package/dist/config.js +573 -581
  4. package/dist/features/contextless-store.js +247 -247
  5. package/dist/features/four-source.js +338 -336
  6. package/dist/features/group-join-request.js +289 -287
  7. package/dist/features/local-models.js +1494 -1467
  8. package/dist/features/style-layer.js +501 -498
  9. package/dist/features/thinking-log.js +71 -69
  10. package/dist/gateway/bootstrap.js +1704 -1652
  11. package/dist/model/settings-reader.js +193 -102
  12. package/dist/shared/paths.js +128 -0
  13. package/dist/shared/settings-io.js +79 -83
  14. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  15. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -794
  16. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  17. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  18. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -444
  19. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  20. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  21. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  22. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  23. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  24. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  25. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  26. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  27. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  28. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  29. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  30. package/package.json +119 -118
  31. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  32. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  33. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  34. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  35. package/scripts/ai-toolkit.py +607 -478
  36. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  37. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  38. package/scripts/chat-archive/build-sft-v4.py +566 -0
  39. package/scripts/chat-archive/build-sft.py +390 -0
  40. package/scripts/chat-archive/eval-sft.py +155 -0
  41. package/scripts/chat-archive/extract-memory.py +143 -0
  42. package/scripts/chat-archive/inventory.py +182 -0
  43. package/scripts/chat-archive/merge-sft.py +114 -0
  44. package/scripts/chat-archive/qce-pull.py +217 -0
  45. package/scripts/chat-archive/qqheader.py +110 -0
  46. package/scripts/chat-archive/qqkey2.py +113 -0
  47. package/scripts/chat-archive/qqprobe.py +153 -0
  48. package/scripts/chat-archive/screen-collect.py +163 -0
  49. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  50. package/scripts/episode.py +529 -0
  51. package/scripts/fan-curve.py +218 -0
  52. package/scripts/fan-guard.cmd +8 -0
  53. package/scripts/fan-mode.py +380 -263
  54. package/scripts/gen-image.py +420 -413
  55. package/scripts/gen-video.py +186 -178
  56. package/scripts/hw-profile.py +175 -0
  57. package/scripts/media-enhance.py +402 -0
  58. package/scripts/memory-audit.py +581 -0
  59. package/scripts/migrate-scope.mjs +140 -139
  60. package/scripts/qq-connect-login.py +133 -0
  61. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  62. package/scripts/qq-ip-sync.py +300 -0
  63. package/scripts/qq-whitelist.py +71 -0
  64. package/scripts/release-all.mjs +636 -509
  65. package/scripts/release-check.mjs +244 -226
  66. package/scripts/secure-room/index.html +334 -0
  67. package/scripts/secure-room/server.py +582 -0
  68. package/scripts/stickers/auto-tag.mjs +161 -0
  69. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  70. package/scripts/train/gguf-quantize.py +92 -0
  71. package/scripts/train/gguf-to-hf.py +112 -0
  72. package/scripts/train/merge-lora.py +51 -0
  73. package/scripts/train/probe-mirrors.sh +12 -0
  74. package/scripts/train/probe-mirrors2.sh +20 -0
  75. package/scripts/train/setup-wsl.sh +23 -0
  76. package/scripts/train/setup-wsl2.sh +25 -0
  77. package/scripts/train/setup-wsl3.sh +22 -0
  78. package/scripts/train/setup-wsl4.sh +22 -0
  79. package/scripts/train/train-lora.py +319 -0
  80. package/dist/_backup_ctx_20261125_183653/dist/config.d.ts +0 -473
  81. package/dist/_backup_ctx_20261125_183653/dist/config.js +0 -450
  82. package/dist/_backup_ctx_20261125_183653/dist/features/contextless-trim.js +0 -304
  83. package/dist/_backup_ctx_20261125_183653/dist/session/session-manager.js +0 -1588
  84. package/dist/_backup_ctx_20261125_183653/dist/transport/inbound.js +0 -1567
  85. package/dist/_backup_ctx_20261125_183653/dist/transport/outbound.js +0 -647
  86. package/scripts/__pycache__/ai-mode.cpython-311.pyc +0 -0
  87. package/scripts/__pycache__/ai-toolkit.cpython-311.pyc +0 -0
  88. package/scripts/__pycache__/comfy_gen.cpython-311.pyc +0 -0
  89. package/scripts/__pycache__/gen-image.cpython-311.pyc +0 -0
  90. package/scripts/__pycache__/gen-video.cpython-311.pyc +0 -0
  91. package/scripts/__pycache__/model-registry.cpython-311.pyc +0 -0
  92. package/scripts/__pycache__/purge-standby.cpython-311.pyc +0 -0
@@ -1,248 +1,248 @@
1
- /**
2
- * contextless-store.ts — 「无上下文模式」的**按会话**开关存储(2026-09-27 主人定)。
3
- *
4
- * 需求(主人原话):
5
- * 「无上下文模式,开启后自动删除历史对话,在 dock 页面但会话里开启」
6
- * —— 在 dock 面板里对**某个会话**开启;开启后该会话**每轮都丢掉历史对话**
7
- * (只保留系统规则 + 「@ 之前 N 条群消息」),用来大幅省 token。
8
- *
9
- * 与其他配置的区别:
10
- * - 全局配置(`config.contextlessMode`)是"所有会话都这样";
11
- * - 本文件是"**只有这个会话**这样"(会话级覆盖,优先级高于全局)。
12
- *
13
- * 存储:`{dataRoot}/.qqbot/contextless.json`,结构 `{ "<sessionKey>": { enabled, window } }`。
14
- * ⚠️ 只放"开关 + 条数",不放任何消息内容 —— 群消息内容由既有的 mediaHistoryBuffer 管。
15
- */
16
- import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
17
- import { diagWrite } from '../shared/diag.js';
18
- import { join, dirname } from 'node:path';
19
- const DEFAULT_SETTING = { enabled: false, window: 5, smart: false };
20
- let storePath = '';
21
- let loaded = false;
22
- const table = new Map();
23
- function ensureDir(p) {
24
- try {
25
- mkdirSync(dirname(p), { recursive: true });
26
- }
27
- catch { /* ignore */ }
28
- }
29
- /**
30
- * 兜底:若没人调过 initContextlessStore(例如"桥"那份模块实例与插件侧不是同一个),
31
- * 就按 DSH_HOME / 家目录推一个路径,**至少要能落盘**(2026-09-27 群聊AI排查发现:
32
- * storePath 为空时 persist() 直接 return,前端照样收到 ok,造成"开关永远存不上")。
33
- */
34
- function ensurePath() {
35
- if (storePath)
36
- return;
37
- try {
38
- // ⚠️ 这只是"最后兜底":正常路径应由 bootstrap(插件侧) 或桥的 loadContextlessStore() 显式 init。
39
- // 兜底路径放在 {DSH_HOME} 下,若真的用到它,说明调用方没 init(两份模块实例的老问题)。
40
- const home = (process.env.DSH_HOME && process.env.DSH_HOME.trim())
41
- || join(process.env.USERPROFILE || process.env.HOME || '.', '.dsh');
42
- storePath = join(home, 'qqbot-contextless.json');
43
- }
44
- catch { /* ignore */ }
45
- }
46
- /** 绑定 dataRoot(apply 时调一次;之后所有读写都落在这里) */
47
- export function initContextlessStore(dataRoot) {
48
- const next = join(dataRoot, '.qqbot', 'contextless.json');
49
- // ⚠️ 2026-09-27 修:多实例共享一个模块级 storePath 时,后 init 的会覆盖前面的
50
- // (实测:A 实例读到了 B 实例的目录)。这里改为**记住多个根**,
51
- // 读的时候把各根合并(同一 key 取先出现的),写的时候写回"该 key 原来所在的根"。
52
- if (storePath && storePath !== next && !roots.includes(next)) {
53
- roots.push(next);
54
- }
55
- else if (!storePath) {
56
- roots.push(next);
57
- }
58
- storePath = next;
59
- loaded = false;
60
- table.clear();
61
- for (const p of roots)
62
- loadFrom(p);
63
- }
64
- /** 已知的数据根文件路径(多实例场景下不止一个) */
65
- const roots = [];
66
- /** 每个 key 归属哪个文件(写回时用它,避免把 A 实例的开关写到 B 实例目录) */
67
- const keyOwner = new Map();
68
- /** 从某个文件读入表(已存在的不覆盖,先到的优先) */
69
- function loadFrom(p) {
70
- try {
71
- if (!p || !existsSync(p))
72
- return;
73
- const raw = JSON.parse(readFileSync(p, 'utf8'));
74
- if (!raw || typeof raw !== 'object')
75
- return;
76
- for (const [key, v] of Object.entries(raw)) {
77
- if (table.has(key))
78
- continue;
79
- const o = v;
80
- table.set(key, {
81
- enabled: o?.enabled === true,
82
- smart: o?.smart === true,
83
- memoMax: Number(o?.memoMax) > 0 ? Number(o.memoMax) : undefined,
84
- window: Number.isFinite(Number(o?.window)) ? Math.max(0, Math.trunc(Number(o.window))) : DEFAULT_SETTING.window,
85
- });
86
- keyOwner.set(key, p); // 记住这个 key 是从哪个文件读来的
87
- }
88
- }
89
- catch { /* 损坏的文件当空表 */ }
90
- }
91
- /** 所有已知文件路径(诊断用) */
92
- export function describeStorePaths() {
93
- try {
94
- ensurePath();
95
- return [storePath, ...roots].filter(Boolean).join(' | ');
96
- }
97
- catch {
98
- return '(err)';
99
- }
100
- }
101
- function load() {
102
- if (loaded)
103
- return;
104
- loaded = true;
105
- ensurePath();
106
- const targets = [storePath, ...roots].filter(Boolean);
107
- for (const p of targets)
108
- loadFrom(p);
109
- }
110
- function persist() {
111
- try {
112
- ensurePath();
113
- if (!storePath)
114
- return;
115
- // 按"key 归属的文件"分组写回:避免多实例互相覆盖(A 实例的开关写进了 B 实例的目录)
116
- const byFile = new Map();
117
- for (const [k, v] of table) {
118
- const owner = keyOwner.get(k) || storePath;
119
- const bucket = byFile.get(owner) ?? {};
120
- bucket[k] = v;
121
- byFile.set(owner, bucket);
122
- }
123
- if (byFile.size === 0)
124
- byFile.set(storePath, {});
125
- for (const [file, obj] of byFile) {
126
- try {
127
- ensureDir(file);
128
- writeFileSync(file, JSON.stringify(obj, null, 2), 'utf8');
129
- }
130
- catch { /* 单个文件失败不影响其它 */ }
131
- }
132
- }
133
- catch { /* 写失败不影响运行 */ }
134
- }
135
- /**
136
- * 落盘追踪(2026-09-27 加,专治"静默失败"):
137
- * 这个功能前后踩了 9 个坑,其中 8 个都不报错 —— 全靠反复试探。
138
- * 现在把「被调用 / 跳过原因 / 结果 / 异常」统统追加到 {dataRoot}/.qqbot/contextless-trace.log,
139
- * 一出问题先看这个文件,别再猜。
140
- */
141
- export function traceContextless(line) {
142
- // ★ 2026-10-06 还债:收口到统一诊断底座(默认关 / 2MB 上限 / 自动轮转 / 只写一个位置)。
143
- // 以前这里**没有任何上限**(实测一路涨到 25 MB),同一条内容还往三个地方各写一份,
144
- // 并且每行都往终端 console.error 刷屏。要排查时开配置项 `diagLog`
145
- // (或 `set DSH_QQBOT_DIAG=1` 重启)即可。
146
- diagWrite('contextless-trace', line);
147
- }
148
- /** 诊断:当前绑定的文件路径(trace 用) */
149
- export function describeStorePath() {
150
- try {
151
- ensurePath();
152
- return storePath || '(empty)';
153
- }
154
- catch {
155
- return '(err)';
156
- }
157
- }
158
- /** 读某会话的设置(未设置 → 默认关) */
159
- export function getContextless(sessionKey) {
160
- ensurePath();
161
- load();
162
- return table.get(sessionKey) ?? { ...DEFAULT_SETTING };
163
- }
164
- /** 写某会话的设置(dock 面板调用;只对有值的字段覆盖) */
165
- export function setContextless(sessionKey, patch) {
166
- ensurePath();
167
- load();
168
- const cur = table.get(sessionKey) ?? { ...DEFAULT_SETTING };
169
- const next = {
170
- enabled: patch.enabled === undefined ? cur.enabled : patch.enabled === true,
171
- window: patch.window === undefined
172
- ? cur.window
173
- : Math.max(0, Math.trunc(Number(patch.window)) || 0),
174
- // 2026-10-01: 「智能判断」子模式(与 window **互斥**)——
175
- // 这里只**存值、不互斥清零**,这样主人在 UI 上来回切换时 window 的旧值不会丢;
176
- // 真正的互斥由读取侧(contextlessSmartOf / keepWindowOf)与面板单选一起保证。
177
- smart: patch.smart === undefined ? (cur.smart === true) : patch.smart === true,
178
- };
179
- table.set(sessionKey, next);
180
- if (!keyOwner.has(sessionKey)) {
181
- try {
182
- ensurePath();
183
- if (storePath)
184
- keyOwner.set(sessionKey, storePath);
185
- }
186
- catch { /* ignore */ }
187
- }
188
- persist();
189
- return next;
190
- }
191
- /** 全表(给 dock 面板列出来) */
192
- export function listContextless() {
193
- load();
194
- const out = {};
195
- for (const [k, v] of table)
196
- out[k] = v;
197
- return out;
198
- }
199
- /** 删某会话的设置 */
200
- export function clearContextless(sessionKey) {
201
- load();
202
- const ok = table.delete(sessionKey);
203
- if (ok)
204
- persist();
205
- return ok;
206
- }
207
- /** 会话是否处于"无上下文模式"(全局开 **或** 该会话单独开) */
208
- export function isContextlessActive(sessionKey, globalEnabled) {
209
- if (globalEnabled === true)
210
- return true;
211
- return getContextless(sessionKey).enabled;
212
- }
213
- /**
214
- * 该会话是否用「智能判断」子模式(2026-10-01 主人设计)。
215
- *
216
- * ⚠️ **与 window 互斥**:返回 true 时,`contextlessWindowOf` 的条数**不生效** ——
217
- * 由 AI 每轮自己判断话题,自主调用 context_compact / context_drop。
218
- * 会话级优先;没设过时用全局默认(config.contextlessSmart)。
219
- */
220
- /** 该会话的备忘条数上限(未设置则 undefined,由默认值兜底) */
221
- export function contextlessMemoMaxOf(sessionKey) {
222
- try {
223
- const v = getContextless(sessionKey).memoMax;
224
- return Number(v) > 0 ? Number(v) : undefined;
225
- }
226
- catch {
227
- return undefined;
228
- }
229
- }
230
- export function contextlessSmartOf(sessionKey, globalDefault) {
231
- try {
232
- const s = getContextless(sessionKey);
233
- if (s.smart !== undefined)
234
- return s.smart === true;
235
- return globalDefault === true;
236
- }
237
- catch {
238
- return globalDefault === true;
239
- }
240
- }
241
- /** 该会话应携带的「@ 之前」群消息条数(会话级优先,其次全局默认 5) */
242
- export function contextlessWindowOf(sessionKey, fallback = 5) {
243
- const s = getContextless(sessionKey);
244
- if (s.enabled)
245
- return s.window;
246
- return Math.max(0, Math.trunc(fallback) || 0);
247
- }
1
+ /**
2
+ * contextless-store.ts — 「无上下文模式」的**按会话**开关存储(2026-09-27 主人定)。
3
+ *
4
+ * 需求(主人原话):
5
+ * 「无上下文模式,开启后自动删除历史对话,在 dock 页面但会话里开启」
6
+ * —— 在 dock 面板里对**某个会话**开启;开启后该会话**每轮都丢掉历史对话**
7
+ * (只保留系统规则 + 「@ 之前 N 条群消息」),用来大幅省 token。
8
+ *
9
+ * 与其他配置的区别:
10
+ * - 全局配置(`config.contextlessMode`)是"所有会话都这样";
11
+ * - 本文件是"**只有这个会话**这样"(会话级覆盖,优先级高于全局)。
12
+ *
13
+ * 存储:`{dataRoot}/.qqbot/contextless.json`,结构 `{ "<sessionKey>": { enabled, window } }`。
14
+ * ⚠️ 只放"开关 + 条数",不放任何消息内容 —— 群消息内容由既有的 mediaHistoryBuffer 管。
15
+ */
16
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
17
+ import { diagWrite } from '../shared/diag.js';
18
+ import { dshHome } from '../shared/paths.js';
19
+ import { join, dirname } from 'node:path';
20
+ const DEFAULT_SETTING = { enabled: false, window: 5, smart: false };
21
+ let storePath = '';
22
+ let loaded = false;
23
+ const table = new Map();
24
+ function ensureDir(p) {
25
+ try {
26
+ mkdirSync(dirname(p), { recursive: true });
27
+ }
28
+ catch { /* ignore */ }
29
+ }
30
+ /**
31
+ * 兜底:若没人调过 initContextlessStore(例如"桥"那份模块实例与插件侧不是同一个),
32
+ * 就按 DSH_HOME / 家目录推一个路径,**至少要能落盘**(2026-09-27 群聊AI排查发现:
33
+ * storePath 为空时 persist() 直接 return,前端照样收到 ok,造成"开关永远存不上")。
34
+ */
35
+ function ensurePath() {
36
+ if (storePath)
37
+ return;
38
+ try {
39
+ // ⚠️ 这只是"最后兜底":正常路径应由 bootstrap(插件侧) 或桥的 loadContextlessStore() 显式 init。
40
+ // 兜底目录统一由 shared/paths.js 的 dshHome() 给(APPDATA / DSH_HOME / XDG / ~/.dsh 都覆盖),
41
+ // 不再自己拼 USERPROFILE——非 Windows 上那个变量根本不存在。
42
+ storePath = join(dshHome(), 'qqbot-contextless.json');
43
+ }
44
+ catch { /* ignore */ }
45
+ }
46
+ /** 绑定 dataRoot(apply 时调一次;之后所有读写都落在这里) */
47
+ export function initContextlessStore(dataRoot) {
48
+ const next = join(dataRoot, '.qqbot', 'contextless.json');
49
+ // ⚠️ 2026-09-27 修:多实例共享一个模块级 storePath 时,后 init 的会覆盖前面的
50
+ // (实测:A 实例读到了 B 实例的目录)。这里改为**记住多个根**,
51
+ // 读的时候把各根合并(同一 key 取先出现的),写的时候写回"该 key 原来所在的根"。
52
+ if (storePath && storePath !== next && !roots.includes(next)) {
53
+ roots.push(next);
54
+ }
55
+ else if (!storePath) {
56
+ roots.push(next);
57
+ }
58
+ storePath = next;
59
+ loaded = false;
60
+ table.clear();
61
+ for (const p of roots)
62
+ loadFrom(p);
63
+ }
64
+ /** 已知的数据根文件路径(多实例场景下不止一个) */
65
+ const roots = [];
66
+ /** 每个 key 归属哪个文件(写回时用它,避免把 A 实例的开关写到 B 实例目录) */
67
+ const keyOwner = new Map();
68
+ /** 从某个文件读入表(已存在的不覆盖,先到的优先) */
69
+ function loadFrom(p) {
70
+ try {
71
+ if (!p || !existsSync(p))
72
+ return;
73
+ const raw = JSON.parse(readFileSync(p, 'utf8'));
74
+ if (!raw || typeof raw !== 'object')
75
+ return;
76
+ for (const [key, v] of Object.entries(raw)) {
77
+ if (table.has(key))
78
+ continue;
79
+ const o = v;
80
+ table.set(key, {
81
+ enabled: o?.enabled === true,
82
+ smart: o?.smart === true,
83
+ memoMax: Number(o?.memoMax) > 0 ? Number(o.memoMax) : undefined,
84
+ window: Number.isFinite(Number(o?.window)) ? Math.max(0, Math.trunc(Number(o.window))) : DEFAULT_SETTING.window,
85
+ });
86
+ keyOwner.set(key, p); // 记住这个 key 是从哪个文件读来的
87
+ }
88
+ }
89
+ catch { /* 损坏的文件当空表 */ }
90
+ }
91
+ /** 所有已知文件路径(诊断用) */
92
+ export function describeStorePaths() {
93
+ try {
94
+ ensurePath();
95
+ return [storePath, ...roots].filter(Boolean).join(' | ');
96
+ }
97
+ catch {
98
+ return '(err)';
99
+ }
100
+ }
101
+ function load() {
102
+ if (loaded)
103
+ return;
104
+ loaded = true;
105
+ ensurePath();
106
+ const targets = [storePath, ...roots].filter(Boolean);
107
+ for (const p of targets)
108
+ loadFrom(p);
109
+ }
110
+ function persist() {
111
+ try {
112
+ ensurePath();
113
+ if (!storePath)
114
+ return;
115
+ // 按"key 归属的文件"分组写回:避免多实例互相覆盖(A 实例的开关写进了 B 实例的目录)
116
+ const byFile = new Map();
117
+ for (const [k, v] of table) {
118
+ const owner = keyOwner.get(k) || storePath;
119
+ const bucket = byFile.get(owner) ?? {};
120
+ bucket[k] = v;
121
+ byFile.set(owner, bucket);
122
+ }
123
+ if (byFile.size === 0)
124
+ byFile.set(storePath, {});
125
+ for (const [file, obj] of byFile) {
126
+ try {
127
+ ensureDir(file);
128
+ writeFileSync(file, JSON.stringify(obj, null, 2), 'utf8');
129
+ }
130
+ catch { /* 单个文件失败不影响其它 */ }
131
+ }
132
+ }
133
+ catch { /* 写失败不影响运行 */ }
134
+ }
135
+ /**
136
+ * 落盘追踪(2026-09-27 加,专治"静默失败"):
137
+ * 这个功能前后踩了 9 个坑,其中 8 个都不报错 —— 全靠反复试探。
138
+ * 现在把「被调用 / 跳过原因 / 结果 / 异常」统统追加到 {dataRoot}/.qqbot/contextless-trace.log,
139
+ * 一出问题先看这个文件,别再猜。
140
+ */
141
+ export function traceContextless(line) {
142
+ // ★ 2026-10-06 还债:收口到统一诊断底座(默认关 / 2MB 上限 / 自动轮转 / 只写一个位置)。
143
+ // 以前这里**没有任何上限**(实测一路涨到 25 MB),同一条内容还往三个地方各写一份,
144
+ // 并且每行都往终端 console.error 刷屏。要排查时开配置项 `diagLog`
145
+ // (或 `set DSH_QQBOT_DIAG=1` 重启)即可。
146
+ diagWrite('contextless-trace', line);
147
+ }
148
+ /** 诊断:当前绑定的文件路径(trace 用) */
149
+ export function describeStorePath() {
150
+ try {
151
+ ensurePath();
152
+ return storePath || '(empty)';
153
+ }
154
+ catch {
155
+ return '(err)';
156
+ }
157
+ }
158
+ /** 读某会话的设置(未设置 → 默认关) */
159
+ export function getContextless(sessionKey) {
160
+ ensurePath();
161
+ load();
162
+ return table.get(sessionKey) ?? { ...DEFAULT_SETTING };
163
+ }
164
+ /** 写某会话的设置(dock 面板调用;只对有值的字段覆盖) */
165
+ export function setContextless(sessionKey, patch) {
166
+ ensurePath();
167
+ load();
168
+ const cur = table.get(sessionKey) ?? { ...DEFAULT_SETTING };
169
+ const next = {
170
+ enabled: patch.enabled === undefined ? cur.enabled : patch.enabled === true,
171
+ window: patch.window === undefined
172
+ ? cur.window
173
+ : Math.max(0, Math.trunc(Number(patch.window)) || 0),
174
+ // 2026-10-01: 「智能判断」子模式(与 window **互斥**)——
175
+ // 这里只**存值、不互斥清零**,这样主人在 UI 上来回切换时 window 的旧值不会丢;
176
+ // 真正的互斥由读取侧(contextlessSmartOf / keepWindowOf)与面板单选一起保证。
177
+ smart: patch.smart === undefined ? (cur.smart === true) : patch.smart === true,
178
+ };
179
+ table.set(sessionKey, next);
180
+ if (!keyOwner.has(sessionKey)) {
181
+ try {
182
+ ensurePath();
183
+ if (storePath)
184
+ keyOwner.set(sessionKey, storePath);
185
+ }
186
+ catch { /* ignore */ }
187
+ }
188
+ persist();
189
+ return next;
190
+ }
191
+ /** 全表(给 dock 面板列出来) */
192
+ export function listContextless() {
193
+ load();
194
+ const out = {};
195
+ for (const [k, v] of table)
196
+ out[k] = v;
197
+ return out;
198
+ }
199
+ /** 删某会话的设置 */
200
+ export function clearContextless(sessionKey) {
201
+ load();
202
+ const ok = table.delete(sessionKey);
203
+ if (ok)
204
+ persist();
205
+ return ok;
206
+ }
207
+ /** 会话是否处于"无上下文模式"(全局开 **或** 该会话单独开) */
208
+ export function isContextlessActive(sessionKey, globalEnabled) {
209
+ if (globalEnabled === true)
210
+ return true;
211
+ return getContextless(sessionKey).enabled;
212
+ }
213
+ /**
214
+ * 该会话是否用「智能判断」子模式(2026-10-01 主人设计)。
215
+ *
216
+ * ⚠️ **与 window 互斥**:返回 true 时,`contextlessWindowOf` 的条数**不生效** ——
217
+ * 由 AI 每轮自己判断话题,自主调用 context_compact / context_drop。
218
+ * 会话级优先;没设过时用全局默认(config.contextlessSmart)。
219
+ */
220
+ /** 该会话的备忘条数上限(未设置则 undefined,由默认值兜底) */
221
+ export function contextlessMemoMaxOf(sessionKey) {
222
+ try {
223
+ const v = getContextless(sessionKey).memoMax;
224
+ return Number(v) > 0 ? Number(v) : undefined;
225
+ }
226
+ catch {
227
+ return undefined;
228
+ }
229
+ }
230
+ export function contextlessSmartOf(sessionKey, globalDefault) {
231
+ try {
232
+ const s = getContextless(sessionKey);
233
+ if (s.smart !== undefined)
234
+ return s.smart === true;
235
+ return globalDefault === true;
236
+ }
237
+ catch {
238
+ return globalDefault === true;
239
+ }
240
+ }
241
+ /** 该会话应携带的「@ 之前」群消息条数(会话级优先,其次全局默认 5) */
242
+ export function contextlessWindowOf(sessionKey, fallback = 5) {
243
+ const s = getContextless(sessionKey);
244
+ if (s.enabled)
245
+ return s.window;
246
+ return Math.max(0, Math.trunc(fallback) || 0);
247
+ }
248
248
  //# sourceMappingURL=contextless-store.js.map