采样第 25 章:纠正 history 窗口误判,补齐私聊 record 与转发节点形态

推翻本轮前一结论:history 单次返回条数不存在「私聊 10 / 群 46」的接口
硬上限。count 实际生效,语义为 min(count, 该会话可读总量);此前把「可读
总量恰好等于返回条数」误判为上限,补发消息后私聊由 10 条增至 14 条即证伪。
单次返回上限至今未测到,对 count 设上限的理由须改为「防止响应过大」。

分页结论维持但证据加强:start_id/end_id/message_id/msg_id 在窗口边界与
窗口中部两种取值下均返回同一页,12 个候选参数名穷举无效,连续翻页推进 0 页。
固化为 GC-015:history 只是本地滑动窗口,事件流实时落库是唯一完整来源。

补齐私聊 record 独立取证(base64://AMR 与新鲜 CDN 直链均三证据通过,本地
路径 1200),MSG-record 的 supports 扩为 group+private。

新增关键约束:node.content 传段数组时 news 降级为「[图片]」
「[该消息类型暂不支持查看]」等占位串、资源标识完全丢失;传 JSON 字符串时
段结构全保留但客户端按字面文本渲染,属语义损坏,发送侧禁止采用。
另记 GC-016(node 段不得与其他段混发,retcode=1400)、
GC-017(占位串禁止当用户正文入库)。

get_forward_msg 对本连接刚发出的 seq=3124/3125 立即调用仍 1200,
排除「消息已过期」的替代解释。

新增 6 个探针(默认 dry-run,写操作需 --yes),修正
history-page-alias-probe 与 seg-census 中会误导复跑的过期定性,
env-local.md 对应条目就地标注作废并给出更正结论。

门禁 capability-check:30 项能力,结构校验 0 错误 0 警告,PASS。

未执行:NAPCAT_WEBUI_PASSWORD 相关路由预检;HTTP 回调与反向 WS 的
NapCat 真实入站采集(按用户决定跳过本机防火墙改动);QQ 端 6 项手动
验证项仍全部待人工;REL-dedup 的重复投递/乱序/断线补推仍未采到。
This commit is contained in:
2026-10-29 17:59:09 +08:00
parent 6e50e026c3
commit b6401116cb
9 changed files with 1006 additions and 24 deletions
+107
View File
@@ -0,0 +1,107 @@
// 段类型普查(纯只读):把群/私聊 history 可读窗口内**每一条消息的每一段**列出来,
// 统计各段类型出现次数,并列出携带该段的消息标识。
//
// 目的:修正「静默丢段」这类只看事件推送就下的结论。
// 事件不推 ≠ 未落库。若某段在 history 里存在,则 QLinker 可通过 history 兜底恢复,
// 与「彻底丢弃」是两种完全不同的实现策略,不得混写。
//
// 只读:不发送任何消息,不修改任何配置。
const WS_URL = process.env.NAPCAT_WS_URL || 'ws://192.168.5.32:16099';
const TOKEN = process.env.NAPCAT_WS_TOKEN;
const GROUP = Number(process.env.PROBE_GROUP || 933280401);
const FRIEND = Number(process.env.PROBE_FRIEND || 2161656029);
if (!TOKEN) { console.error('缺少环境变量 NAPCAT_WS_TOKEN。凭据不得硬编码。'); process.exit(1); }
const fs = await import('node:fs');
const path = await import('node:path');
const OUT_DIR = process.env.PROBE_OUT || 'local';
fs.mkdirSync(OUT_DIR, { recursive: true });
const OUT = path.join(OUT_DIR, `seg-census-${new Date().toISOString().replace(/[:.]/g, '-')}.jsonl`);
const say = (...a) => console.log(...a);
const ws = new WebSocket(`${WS_URL.replace(/\/$/, '')}/?access_token=${encodeURIComponent(TOKEN)}`);
const pending = new Map();
let opened = false, authed = false;
ws.onopen = () => { opened = true; };
ws.onmessage = (ev) => {
let o; try { o = JSON.parse(String(ev.data)); } catch { return; }
if (o.echo && pending.has(o.echo)) { pending.get(o.echo).resolve(o); pending.delete(o.echo); return; }
if (o.post_type === 'meta_event' && o.meta_event_type === 'lifecycle') authed = true;
};
for (let i = 0; i < 100 && !opened; i++) await new Promise((r) => setTimeout(r, 100));
if (!opened) { console.error('连接超时'); process.exit(1); }
for (let i = 0; i < 100 && !authed; i++) await new Promise((r) => setTimeout(r, 100));
say('认证=' + authed);
if (!authed) { console.error('未收到 lifecycle,中止。'); process.exit(2); }
const api = (action, params, ms = 30000) => new Promise((resolve) => {
const echo = `sc-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
const to = setTimeout(() => { pending.delete(echo); resolve({ __timeout: true }); }, ms);
pending.set(echo, { resolve: (o) => { clearTimeout(to); resolve(o); }, to });
ws.send(JSON.stringify({ action, params, echo }));
});
const rec = (o) => { fs.appendFileSync(OUT, JSON.stringify(o) + '\n'); return o; };
const TARGETS = ['poke', 'music', 'location', 'at', 'record', 'video', 'image', 'file',
'json', 'xml', 'node', 'reply', 'face', 'forward', 'contact', 'dice', 'shake', 'miniapp', 'marketface'];
async function census(action, base, label) {
// count 语义为 min(count, 该会话可读总量),取 200 以覆盖当前可读全窗口。
// 返回条数取决于 NapCat 本地保留量,不是接口上限(见 GC-015)。
const r = await api(action, { ...base, count: 200 });
const msgs = r?.data?.messages ?? [];
say(`\n===== ${label} (${action}) retcode=${r.retcode} 共 ${msgs.length} 条 =====`);
if (!msgs.length) { say(' 窗口为空'); return {}; }
const seqs = msgs.map((m) => Number(m.real_seq));
say(` real_seq 范围 ${Math.min(...seqs)}..${Math.max(...seqs)}(升序=${Number(msgs[0].real_seq) < Number(msgs[msgs.length - 1].real_seq)})`);
const byType = new Map();
for (const m of msgs) {
for (const s of (m.message ?? [])) {
if (!byType.has(s.type)) byType.set(s.type, []);
byType.get(s.type).push({
seq: String(m.real_seq), message_id: m.message_id,
sender: m.sender?.user_id ?? null,
data_preview: JSON.stringify(s.data ?? {}).slice(0, 160),
});
}
}
say(' 段类型分布:');
for (const [t, arr] of [...byType.entries()].sort((a, b) => b[1].length - a[1].length)) {
say(` ${t.padEnd(12)} ${String(arr.length).padStart(3)} 条 例 seq=${arr[0].seq} ${arr[0].data_preview.slice(0, 90)}`);
}
const missing = TARGETS.filter((t) => !byType.has(t));
say(' 窗口内**未出现**的目标段类型:' + (missing.join(', ') || '(无)'));
for (const [t, arr] of byType.entries()) {
rec({ kind: 'census', scope: label, seg_type: t, count: arr.length, samples: arr.slice(0, 6) });
}
rec({ kind: 'census_window', scope: label, action, total: msgs.length,
seq_min: String(Math.min(...seqs)), seq_max: String(Math.max(...seqs)),
absent_types: missing });
return byType;
}
const g = await census('get_group_msg_history', { group_id: GROUP }, 'group');
const p = await census('get_friend_msg_history', { user_id: FRIEND }, 'private');
// 重点核对:此前定性为「静默丢段」的三类,在 history 里到底有没有
say('\n===== 静默丢段定性复核(事件无推送,但 history 是否有?)=====');
for (const [label, byType] of [['group', g], ['private', p]]) {
for (const t of ['poke', 'location', 'music', 'record', 'file']) {
const arr = byType.get(t);
say(` ${label.padEnd(8)} ${t.padEnd(9)} ${arr ? 'history 中存在 ' + arr.length + ' 条 → 事件缺失但可回读' : 'history 中不存在'}`);
}
}
// 私聊窗口只有 10 条,把全部原文打出来,便于确认私聊段矩阵的第三证据是否被窗口限制
say('\n===== 私聊窗口全部消息(窗口上限 10,逐条列出)=====');
const pr = await api('get_friend_msg_history', { user_id: FRIEND, count: 200 });
for (const m of pr?.data?.messages ?? []) {
say(` seq=${m.real_seq} mid=${m.message_id} 段=${(m.message ?? []).map((s) => s.type).join('+')} `
+ `文=${(m.message ?? []).filter((s) => s.type === 'text').map((s) => s.data?.text).join('').slice(0, 40)}`);
}
say('\n结果 -> ' + OUT);
try { ws.close(); } catch {}
process.exit(0);