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
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scenario-detect.js — 「任务型 vs 闲聊型」会话判定(2026-11-25,任务 A)
|
|
3
|
+
*
|
|
4
|
+
* 背景:主人反馈固定 60 轮换档太粗暴 —— 做任务的会话 100 多轮被换掉不行,纯聊天又要能撑几百轮。
|
|
5
|
+
* 这里用**最近 N 条可观测信号**打分,给出可解释的判定(不是随机、不是拍脑袋):
|
|
6
|
+
*
|
|
7
|
+
* 任务型加分:工具调用 / 代码块 / 长消息(>200字) / 文件名·路径 / 反复追问同一目标 / 指令动词
|
|
8
|
+
* 闲聊型减分:短消息占比高 / 表情包·哈哈 / 连续「嗯哦草」这类单字回合
|
|
9
|
+
*
|
|
10
|
+
* 输出 { mode, score, threshold, reasons[], stats },reasons 里每条都是 {key,label,weight,hit,detail},
|
|
11
|
+
* 日志/自测里直接打出来就能解释「为什么算任务型」。
|
|
12
|
+
*
|
|
13
|
+
* 纯函数 + 只读 agent 会话,不写盘、不联网、不调模型。
|
|
14
|
+
*/
|
|
15
|
+
import { recentMessagesOf } from './contextless-trim.js';
|
|
16
|
+
|
|
17
|
+
export const MODE_TASK = 'task';
|
|
18
|
+
export const MODE_CHAT = 'chat';
|
|
19
|
+
|
|
20
|
+
/** 参与判定的最近消息条数(主人建议 12) */
|
|
21
|
+
export const DEFAULT_SIGNAL_WINDOW = 12;
|
|
22
|
+
/** 达到多少分算任务型 */
|
|
23
|
+
export const DEFAULT_TASK_THRESHOLD = 3;
|
|
24
|
+
|
|
25
|
+
/** 扫描 surface 节点时往回看多少个(工具事件不算消息,要单独数) */
|
|
26
|
+
const DEFAULT_NODE_SCAN = 80;
|
|
27
|
+
|
|
28
|
+
const LONG_MSG_CHARS = 200;
|
|
29
|
+
|
|
30
|
+
/** 指令动词(用户在派活) */
|
|
31
|
+
const INSTRUCTION_RE = /(帮我|帮忙|改一下|改成|写个|写一个|写个脚本|修一下|修复|跑一下|跑跑|部署|实现|加个|加上|删掉|查一下|排查|调试|报错|怎么弄|怎么改|能不能做|做一个|生成|导出|重构|提交|push|commit|install|npm |node )/i;
|
|
32
|
+
/** 路径 / 文件名 */
|
|
33
|
+
const PATH_RE = /(?:[A-Za-z]:[\\/][^\s,。;、!?"'))】]+)|(?:(?:[\w.-]+[\\/]){2,}[\w-]+[\.][A-Za-z0-9]{1,6}\b)|(?:\b[\w.-]+\.(?:js|mjs|cjs|ts|tsx|json|md|py|yml|yaml|toml|txt|sh|ps1|bat|ini|log|css|html)\b)/;
|
|
34
|
+
/** 代码块 / 终端痕迹 */
|
|
35
|
+
const CODE_RE = /(```|^\s*[$>]\s+\S|^\s*(?:const|let|function|import|export|class|def|return)\s)/m;
|
|
36
|
+
/** 闲聊痕迹(表情包、哈哈、单字回合) */
|
|
37
|
+
const CHAT_RE = /(\[STICKER:[^\]]+\]|哈哈+|2333|笑死|草|草草|呜呜|awsl|yyds|xswl)/i;
|
|
38
|
+
const SHORT_CHAT_RE = /^(嗯+|哦+|啊+|好+|行+|?+|\?+|收到|好的|ok|OK|在吗|早|晚安|睡了)$/;
|
|
39
|
+
|
|
40
|
+
function intOf(v, dflt, min, max) {
|
|
41
|
+
const n = Number(v);
|
|
42
|
+
if (!Number.isFinite(n))
|
|
43
|
+
return dflt;
|
|
44
|
+
return Math.min(max, Math.max(min, Math.round(n)));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function clip(text, max) {
|
|
48
|
+
const t = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
49
|
+
return t.length > max ? t.slice(0, Math.max(1, max - 1)) + '…' : t;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 从事件里抠出纯文本(兼容 content blocks / text 字段) */
|
|
53
|
+
function textOfEvent(ev) {
|
|
54
|
+
if (!ev || typeof ev !== 'object')
|
|
55
|
+
return '';
|
|
56
|
+
if (typeof ev.text === 'string')
|
|
57
|
+
return ev.text;
|
|
58
|
+
const blocks = Array.isArray(ev.content) ? ev.content : [];
|
|
59
|
+
const parts = [];
|
|
60
|
+
for (const b of blocks) {
|
|
61
|
+
if (b && b.type === 'text' && typeof b.text === 'string')
|
|
62
|
+
parts.push(b.text);
|
|
63
|
+
}
|
|
64
|
+
return parts.join('\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 只读采集最近会话信号:消息文本 + 工具事件数。
|
|
69
|
+
* agent 读不到就返回空信号(调用方按「不确定」处理,不误判成任务型)。
|
|
70
|
+
* @returns {{messages:Array<{role:string,text:string}>, toolCalls:number, scanned:number}}
|
|
71
|
+
*/
|
|
72
|
+
export function collectSessionSignals(agent, { msgLimit = DEFAULT_SIGNAL_WINDOW, nodeScan = DEFAULT_NODE_SCAN } = {}) {
|
|
73
|
+
const messages = recentMessagesOf(agent, intOf(msgLimit, DEFAULT_SIGNAL_WINDOW, 1, 60));
|
|
74
|
+
let toolCalls = 0;
|
|
75
|
+
let scanned = 0;
|
|
76
|
+
try {
|
|
77
|
+
const sess = agent?.session;
|
|
78
|
+
const nodes = sess?.surface?.nodes;
|
|
79
|
+
if (Array.isArray(nodes) && nodes.length > 0) {
|
|
80
|
+
const from = Math.max(0, nodes.length - intOf(nodeScan, DEFAULT_NODE_SCAN, 1, 500));
|
|
81
|
+
for (let i = from; i < nodes.length; i++) {
|
|
82
|
+
const ev = sess.eventAt?.(nodes[i]);
|
|
83
|
+
if (!ev)
|
|
84
|
+
continue;
|
|
85
|
+
scanned++;
|
|
86
|
+
const type = String(ev.type ?? '');
|
|
87
|
+
if (type.startsWith('tool/'))
|
|
88
|
+
toolCalls++;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch { /* 读不到就按 0 算 */ }
|
|
93
|
+
return { messages, toolCalls, scanned };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 中文二元组(不引分词库;够用的粗粒度「同目标」判据) */
|
|
97
|
+
function bigramsOf(text) {
|
|
98
|
+
const s = String(text ?? '').replace(/[\s\p{P}\p{S}]+/gu, '');
|
|
99
|
+
const out = new Set();
|
|
100
|
+
for (let i = 0; i + 2 <= s.length; i++)
|
|
101
|
+
out.add(s.slice(i, i + 2));
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 在 ≥2 条**用户**消息里重复出现的二元组 → 说明在反复追同一件事 */
|
|
106
|
+
function repeatedGoalStats(messages) {
|
|
107
|
+
const users = (Array.isArray(messages) ? messages : [])
|
|
108
|
+
.filter((m) => String(m?.role ?? '') !== 'assistant')
|
|
109
|
+
.map((m) => String(m?.text ?? ''));
|
|
110
|
+
if (users.length < 2)
|
|
111
|
+
return { repeat: 0, top: '' };
|
|
112
|
+
const seen = new Map();
|
|
113
|
+
for (const text of users) {
|
|
114
|
+
for (const g of bigramsOf(text)) {
|
|
115
|
+
if (!seen.has(g))
|
|
116
|
+
seen.set(g, new Set());
|
|
117
|
+
seen.get(g).add(text);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let best = { n: 0, gram: '' };
|
|
121
|
+
for (const [gram, set] of seen) {
|
|
122
|
+
if (set.size > best.n) {
|
|
123
|
+
// 停用二元组(的/了/是 这类高频虚词不算「同一目标」)
|
|
124
|
+
if (/^[的了是我你他她它们这那有在就都也还和与把被给对从到很太更最不没吗呢吧啊哦嗯]+$/.test(gram))
|
|
125
|
+
continue;
|
|
126
|
+
best = { n: set.size, gram };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { repeat: best.n, top: best.gram };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 核心判定:喂最近消息 + 工具调用数,返回可解释打分。
|
|
134
|
+
* @param {{messages?:Array<{role:string,text:string}>, toolCalls?:number, threshold?:number}} input
|
|
135
|
+
*/
|
|
136
|
+
export function classifyScenario({ messages, toolCalls = 0, threshold } = {}) {
|
|
137
|
+
const list = (Array.isArray(messages) ? messages : [])
|
|
138
|
+
.map((m) => ({ role: String(m?.role ?? 'user'), text: String(m?.text ?? '') }))
|
|
139
|
+
.filter((m) => m.text.trim() !== '');
|
|
140
|
+
const users = list.filter((m) => m.role !== 'assistant');
|
|
141
|
+
const th = Number.isFinite(Number(threshold)) ? Number(threshold) : DEFAULT_TASK_THRESHOLD;
|
|
142
|
+
const reasons = [];
|
|
143
|
+
let score = 0;
|
|
144
|
+
|
|
145
|
+
// 1) 工具调用(最强信号:只有真在干活才会出工具)
|
|
146
|
+
const tools = Math.max(0, Math.round(Number(toolCalls) || 0));
|
|
147
|
+
const toolHit = Math.min(2.7, tools * 0.9);
|
|
148
|
+
score += toolHit;
|
|
149
|
+
reasons.push({
|
|
150
|
+
key: 'tool', label: '工具调用', weight: Number(toolHit.toFixed(2)), hit: tools > 0,
|
|
151
|
+
detail: tools > 0 ? `最近 ${tools} 次工具调用` : '最近无工具调用',
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// 2) 代码块 / 终端痕迹
|
|
155
|
+
const codeMsgs = list.filter((m) => CODE_RE.test(m.text)).length;
|
|
156
|
+
const codeHit = Math.min(2, codeMsgs * 0.7);
|
|
157
|
+
if (codeMsgs > 0) {
|
|
158
|
+
score += codeHit;
|
|
159
|
+
reasons.push({ key: 'code', label: '代码/命令', weight: Number(codeHit.toFixed(2)), hit: true, detail: `${codeMsgs} 条含代码或命令` });
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
reasons.push({ key: 'code', label: '代码/命令', weight: 0, hit: false, detail: '无' });
|
|
163
|
+
|
|
164
|
+
// 3) 长消息(>200 字 = 在描述需求/贴报错)
|
|
165
|
+
const longMsgs = users.filter((m) => m.text.length > LONG_MSG_CHARS).length;
|
|
166
|
+
const longHit = Math.min(2.7, longMsgs * 0.9);
|
|
167
|
+
if (longMsgs > 0) {
|
|
168
|
+
score += longHit;
|
|
169
|
+
reasons.push({ key: 'long', label: '长消息(>200字)', weight: Number(longHit.toFixed(2)), hit: true, detail: `${longMsgs} 条` });
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
reasons.push({ key: 'long', label: '长消息(>200字)', weight: 0, hit: false, detail: '无' });
|
|
173
|
+
|
|
174
|
+
// 4) 文件名 / 路径
|
|
175
|
+
const pathMsgs = users.filter((m) => PATH_RE.test(m.text)).length;
|
|
176
|
+
const pathHit = Math.min(2.4, pathMsgs * 0.8);
|
|
177
|
+
if (pathMsgs > 0) {
|
|
178
|
+
score += pathHit;
|
|
179
|
+
reasons.push({ key: 'path', label: '文件路径', weight: Number(pathHit.toFixed(2)), hit: true, detail: `${pathMsgs} 条提到路径/文件名` });
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
reasons.push({ key: 'path', label: '文件路径', weight: 0, hit: false, detail: '无' });
|
|
183
|
+
|
|
184
|
+
// 5) 反复追问同一目标
|
|
185
|
+
const rep = repeatedGoalStats(users);
|
|
186
|
+
const repHit = rep.repeat >= 2 ? Math.min(2, 0.8 + rep.repeat * 0.4) : 0;
|
|
187
|
+
if (repHit > 0) {
|
|
188
|
+
score += repHit;
|
|
189
|
+
reasons.push({ key: 'repeat', label: '反复同一目标', weight: Number(repHit.toFixed(2)), hit: true, detail: `「${rep.top}」出现在 ${rep.repeat} 条消息` });
|
|
190
|
+
}
|
|
191
|
+
else
|
|
192
|
+
reasons.push({ key: 'repeat', label: '反复同一目标', weight: 0, hit: false, detail: '无' });
|
|
193
|
+
|
|
194
|
+
// 6) 指令动词
|
|
195
|
+
const instrMsgs = users.filter((m) => INSTRUCTION_RE.test(m.text)).length;
|
|
196
|
+
const instrHit = Math.min(1.8, instrMsgs * 0.6);
|
|
197
|
+
if (instrMsgs > 0) {
|
|
198
|
+
score += instrHit;
|
|
199
|
+
reasons.push({ key: 'instruct', label: '指令动词', weight: Number(instrHit.toFixed(2)), hit: true, detail: `${instrMsgs} 条像在派活` });
|
|
200
|
+
}
|
|
201
|
+
else
|
|
202
|
+
reasons.push({ key: 'instruct', label: '指令动词', weight: 0, hit: false, detail: '无' });
|
|
203
|
+
|
|
204
|
+
// 7) 闲聊减分:短消息占比 + 表情/哈哈
|
|
205
|
+
const avgLen = users.length > 0 ? users.reduce((n, m) => n + m.text.length, 0) / users.length : 0;
|
|
206
|
+
const shortRatio = users.length > 0 ? users.filter((m) => m.text.length <= 12).length / users.length : 0;
|
|
207
|
+
const chatMsgs = list.filter((m) => CHAT_RE.test(m.text)).length;
|
|
208
|
+
const pureShort = users.filter((m) => SHORT_CHAT_RE.test(m.text.trim())).length;
|
|
209
|
+
let chatPenalty = 0;
|
|
210
|
+
if (shortRatio >= 0.6 && avgLen <= 14)
|
|
211
|
+
chatPenalty += 1.2;
|
|
212
|
+
if (chatMsgs >= 2)
|
|
213
|
+
chatPenalty += Math.min(1.2, chatMsgs * 0.4);
|
|
214
|
+
if (pureShort >= 2)
|
|
215
|
+
chatPenalty += Math.min(1, pureShort * 0.3);
|
|
216
|
+
chatPenalty = Math.min(2.4, chatPenalty);
|
|
217
|
+
if (chatPenalty > 0) {
|
|
218
|
+
score -= chatPenalty;
|
|
219
|
+
reasons.push({ key: 'chat', label: '闲聊痕迹(减分)', weight: -Number(chatPenalty.toFixed(2)), hit: true, detail: `短句占比 ${(shortRatio * 100).toFixed(0)}%,表情/哈哈 ${chatMsgs} 条` });
|
|
220
|
+
}
|
|
221
|
+
else
|
|
222
|
+
reasons.push({ key: 'chat', label: '闲聊痕迹(减分)', weight: 0, hit: false, detail: '无' });
|
|
223
|
+
|
|
224
|
+
const finalScore = Number(score.toFixed(2));
|
|
225
|
+
const mode = finalScore >= th ? MODE_TASK : MODE_CHAT;
|
|
226
|
+
return {
|
|
227
|
+
mode,
|
|
228
|
+
score: finalScore,
|
|
229
|
+
threshold: th,
|
|
230
|
+
reasons,
|
|
231
|
+
stats: {
|
|
232
|
+
messages: list.length,
|
|
233
|
+
userMessages: users.length,
|
|
234
|
+
toolCalls: tools,
|
|
235
|
+
avgUserChars: Math.round(avgLen),
|
|
236
|
+
shortRatio: Number(shortRatio.toFixed(2)),
|
|
237
|
+
codeMsgs,
|
|
238
|
+
longMsgs,
|
|
239
|
+
pathMsgs,
|
|
240
|
+
instrMsgs,
|
|
241
|
+
chatMsgs,
|
|
242
|
+
repeat: rep.repeat,
|
|
243
|
+
repeatGram: rep.top,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 一行解释(日志 / 自测用):mode=task score=4.6 | tool+2.70 code+1.40 chat-1.20 */
|
|
249
|
+
export function explainScenario(result) {
|
|
250
|
+
if (!result || typeof result !== 'object')
|
|
251
|
+
return 'mode=? score=?';
|
|
252
|
+
const parts = (Array.isArray(result.reasons) ? result.reasons : [])
|
|
253
|
+
.filter((r) => r && Number(r.weight) !== 0)
|
|
254
|
+
.map((r) => `${r.key}${r.weight > 0 ? '+' : ''}${Number(r.weight).toFixed(2)}`);
|
|
255
|
+
return `mode=${result.mode} score=${Number(result.score).toFixed(2)}/${result.threshold}`
|
|
256
|
+
+ (parts.length > 0 ? ' | ' + parts.join(' ') : ' | 无信号');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** 任务上下文锚点:待办 / 文件路径 / 报错原文 —— 换档时**必须**留住的东西 */
|
|
260
|
+
const ERROR_RE = /(error|Error|ERROR|报错|报错原文|异常|failed|Failed|FAILED|exception|Traceback|ECONN|ETIMEDOUT|HTTP \d{3}|exit code|超时|失败|无法|不能|崩了|炸了)/;
|
|
261
|
+
const TODO_RE = /(待办|TODO|todo|还没|尚未|没做完|没完成|下次|回头|记得|要改|需要改|待会|稍后|明天|晚点|接着|继续|别忘了)/;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @returns {{todos:string[], paths:string[], errors:string[], any:boolean}}
|
|
265
|
+
*/
|
|
266
|
+
export function extractTaskAnchors(messages, { maxEach = 4, maxLen = 120 } = {}) {
|
|
267
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
268
|
+
const todos = [];
|
|
269
|
+
const paths = [];
|
|
270
|
+
const errors = [];
|
|
271
|
+
const uniqPush = (arr, v) => {
|
|
272
|
+
const t = clip(v, maxLen);
|
|
273
|
+
if (t && !arr.includes(t))
|
|
274
|
+
arr.push(t);
|
|
275
|
+
};
|
|
276
|
+
for (const m of list) {
|
|
277
|
+
const text = String(m?.text ?? '');
|
|
278
|
+
if (!text)
|
|
279
|
+
continue;
|
|
280
|
+
const lines = text.split(/[\n。;;]+/);
|
|
281
|
+
for (const line of lines) {
|
|
282
|
+
const l = line.trim();
|
|
283
|
+
if (!l)
|
|
284
|
+
continue;
|
|
285
|
+
if (l.length < 4)
|
|
286
|
+
continue;
|
|
287
|
+
if (TODO_RE.test(l))
|
|
288
|
+
uniqPush(todos, l);
|
|
289
|
+
if (ERROR_RE.test(l))
|
|
290
|
+
uniqPush(errors, l);
|
|
291
|
+
if (PATH_RE.test(l)) {
|
|
292
|
+
const m2 = l.match(PATH_RE);
|
|
293
|
+
uniqPush(paths, m2 ? m2[0] : l);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
todos: todos.slice(-maxEach),
|
|
299
|
+
paths: paths.slice(-maxEach),
|
|
300
|
+
errors: errors.slice(-maxEach),
|
|
301
|
+
any: todos.length + paths.length + errors.length > 0,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** 把锚点拼成摘要末尾的一句「硬信息」,没有就返回空串 */
|
|
306
|
+
export function formatTaskAnchors(anchors) {
|
|
307
|
+
const a = anchors || {};
|
|
308
|
+
const seg = [];
|
|
309
|
+
const errors = Array.isArray(a.errors) ? a.errors.filter(Boolean) : [];
|
|
310
|
+
// 同一句话既像待办又像报错时只留报错(报错原文更硬),别把同一句抄两遍占预算
|
|
311
|
+
const todos = (Array.isArray(a.todos) ? a.todos : [])
|
|
312
|
+
.filter(Boolean)
|
|
313
|
+
.filter((t) => !errors.some((e) => String(e).includes(String(t)) || String(t).includes(String(e))));
|
|
314
|
+
if (todos.length > 0)
|
|
315
|
+
seg.push('待办:' + todos.join(';'));
|
|
316
|
+
if (errors.length > 0)
|
|
317
|
+
seg.push('报错/卡点:' + errors.join(';'));
|
|
318
|
+
if (Array.isArray(a.paths) && a.paths.length > 0)
|
|
319
|
+
seg.push('文件:' + a.paths.join('、'));
|
|
320
|
+
return seg.join('|');
|
|
321
|
+
}
|
|
@@ -76,7 +76,11 @@ export function startScheduler(manager, config, logger) {
|
|
|
76
76
|
const pad = (n) => String(n).padStart(2, '0');
|
|
77
77
|
const ts = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
|
78
78
|
const rawPrompt = task.prompt?.trim() || '在吗~ 出来说说话吧';
|
|
79
|
-
|
|
79
|
+
// 2026-11-23:原样注入时,模型会把「[定时任务 23:30] 今天辛苦一天啦…」当成
|
|
80
|
+
// *已经发过的提醒记录*,进而回一句「这条我已经回过了」然后静默(日常问候丢失)。
|
|
81
|
+
// 这里显式声明「这是现在要做的事」,别让它当成历史。
|
|
82
|
+
const trigger = `[定时任务 ${ts}] 到点了。下面这句是**现在**要你做的事/要说的话,`
|
|
83
|
+
+ `不是历史消息、不是提醒记录,也不要当成已经发过的内容:${rawPrompt}`;
|
|
80
84
|
const fakeMsg = {
|
|
81
85
|
kind: scope,
|
|
82
86
|
senderId: scope === 'c2c' ? target.targetId : 'master',
|
|
@@ -87,6 +91,9 @@ export function startScheduler(manager, config, logger) {
|
|
|
87
91
|
groupOpenid: scope === 'group' ? target.targetId : undefined,
|
|
88
92
|
msgType: 0,
|
|
89
93
|
attachments: undefined,
|
|
94
|
+
// 2026-11-23:定时唤醒必须真的进站 —— 否则群里会被价值闸门
|
|
95
|
+
// (gate=block / worth=false)直接判「不值得回」,问候永远发不出去。
|
|
96
|
+
forceWake: true,
|
|
90
97
|
};
|
|
91
98
|
await handleInbound(fakeMsg, manager, config, logger, undefined);
|
|
92
99
|
logger.info(`[scheduler] injected inbound → handleInbound: task=${task.id} key=${key}`);
|