阶段 01(基线冻结与环境核验) - 新增 docs/decision-baseline.md:DEC-001~408 决策登记、TBD 处置、 GAP-01~18 文档同步清单、NEED-01~10 阻塞项闭环 - DEC-005 定稿:NapCat 维持 latest-stable,升级强制全量回归(选项 B) - DEC-006 定稿:开发期接受 MinIO 明文 HTTP + root 凭据,正式环境 TLS 与受限子账号列为部署前置条件 - 新增 .env.example(仅占位值)、.gitignore(排除 env-local.md 与 local/) - 实测环境:JDK 21 / MySQL 8.0.46(lower_case_table_names=1 导致库名 强制小写,影响首版初始化命名)/ MinIO 建桶读写全通 阶段 02(NapCat 4.18.41 协议实测,正向 WebSocket) - 三证据矩阵(API retcode + 事件段 + history 回读段)覆盖 27 项能力 - 关键结论:retcode=0 不等于送达(poke/location/私聊 at 静默丢段); file 段成功但零事件回推;forward 容器无效须用并列 node 段且 content 必须为段数组;get_forward_msg 读回为能力缺口; record 受上游解码能力限制;music 降级为 text;URL 形式媒体可用 但 rkey 具时效;撤回只能用 delete_msg 且 history 不回显撤回状态; 通知类事件无 real_seq,去重键需分类设计 - 安全发现:get_ai_record 名义查询实际会真实发送语音,已标 severity high - 上游自检 API 不可信(can_send_record 返回 yes=true 与实测矛盾) 能力基线与回归门禁(DEC-005 落地) - 新增 docs/capability-baseline.json:27 项能力机器可读基线 + 8 条跨能力硬约束 GC-001~008,状态不得留空 - 新增 tools/probe/capability-check.mjs:离线结构校验 PASS(0 错误 0 警告,探针覆盖 22/27);漂移比对 17 项自动一致、0 漂移、 1 缺测、4 人工确认 → PASS;门禁有效性已做红/绿验证 - 新增/修复探测脚本 20 个,均默认 dry-run、写操作需 --yes、 凭据仅从环境变量读取 未验证项保持未验证:反向 WS / HTTP 回调 / HTTP API 三条入站链路受阻于 网络拓扑;重复投递、乱序、断线重连补推及需 QQ 端人工操作的通知类事件 未采集,去重键与「结果未知」状态机不得定稿。
157 lines
8.3 KiB
JavaScript
157 lines
8.3 KiB
JavaScript
// 矩阵跑完后的定向补测,只针对三个悬而未决的点:
|
||
// 1) 服务端合并转发的 node.content 形态(段数组 vs JSON 字符串)——上一轮传字符串被当字面文本渲染
|
||
// 2) get_forward_msg 的正确参数名(穷举常见命名,拿到成功结构或全部失败证据)
|
||
// 3) 语音能力旁证:send_group_ai_record(NapCat 官方 TTS)能否成功,用于区分
|
||
// 「record 段不可用」与「NapCat 运行环境缺解码器」
|
||
// 默认 dry-run,--yes 才真实发送。凭据只从环境变量读取。
|
||
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
|
||
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);
|
||
const SELF = Number(process.env.PROBE_SELF || 3575608514);
|
||
const DO_WRITE = process.argv.includes('--yes');
|
||
const OUT_DIR = process.env.PROBE_OUT || 'local';
|
||
if (!TOKEN) { console.error('缺少环境变量 NAPCAT_WS_TOKEN。凭据不得硬编码。'); process.exit(1); }
|
||
|
||
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||
fs.mkdirSync(OUT_DIR, { recursive: true });
|
||
const OUT = path.join(OUT_DIR, `followup-${stamp}.jsonl`);
|
||
const say = (...a) => console.log(...a);
|
||
|
||
const pending = new Map();
|
||
let opened = false;
|
||
let authed = false;
|
||
const events = [];
|
||
const ws = new WebSocket(`${WS_URL.replace(/\/$/, '')}/?access_token=${encodeURIComponent(TOKEN)}`);
|
||
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; return; }
|
||
if (o.post_type === 'meta_event') return;
|
||
events.push({ el: Date.now(), data: o });
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'event', t: new Date().toISOString(), data: o }) + '\n');
|
||
};
|
||
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 && DO_WRITE) { console.error('未确认认证,中止。'); process.exit(2); }
|
||
|
||
const api = (action, params, ms = 30000) => new Promise((resolve) => {
|
||
const echo = `fu-${action}-${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 nodeArr = (label) => [
|
||
{ type: 'node', data: { type: 'node', user_id: String(SELF), nickname: '雪珂',
|
||
content: [{ type: 'text', data: { text: `${label}-A` } }] } },
|
||
{ type: 'node', data: { type: 'node', user_id: String(FRIEND), nickname: '小王',
|
||
content: [{ type: 'text', data: { text: `${label}-B` } }] } },
|
||
];
|
||
|
||
const JOBS = [
|
||
{ id: 'fwd_group_content_arr', desc: 'send_group_forward_msg + node.content 为段数组',
|
||
action: 'send_group_forward_msg', params: () => ({ group_id: GROUP, messages: nodeArr('数组形') }) },
|
||
{ id: 'fwd_seg_parallel', desc: '并列 node 段(第19章已证明生效,作为对照基准)',
|
||
action: 'send_group_msg', params: () => ({ group_id: GROUP, message: [
|
||
...nodeArr('并列段'), { type: 'text', data: { text: '[QLf:fwd_seg_parallel]' } }] }) },
|
||
{ id: 'ai_record_group', desc: 'send_group_ai_record(官方 TTS 语音,群)',
|
||
action: 'send_group_ai_record', params: () => ({ group_id: GROUP, character: 'lucy-voice-houge', text: 'QLinker 语音能力旁证' }) },
|
||
];
|
||
|
||
say(`\n模式=${DO_WRITE ? '真实发送' : 'DRY-RUN'}\n`);
|
||
const sent = {};
|
||
for (const j of JOBS) {
|
||
if (!DO_WRITE) { say(`${j.id.padEnd(22)} [计划] ${j.desc}`); continue; }
|
||
const t0 = Date.now();
|
||
const r = await api(j.action, j.params());
|
||
if (j.action.includes('ai_record')) {
|
||
const rec = { id: j.id, desc: j.desc, retcode: r.__timeout ? 'TIMEOUT' : r.retcode,
|
||
message: r.message ?? r.wording ?? '', data_preview: typeof r.data === 'string' ? r.data.slice(0, 90) : JSON.stringify(r.data)?.slice(0, 120) };
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'result', ...rec }) + '\n');
|
||
say(`${j.id.padEnd(22)} retcode=${String(rec.retcode).padEnd(7)} ${String(rec.message).slice(0, 50)} data=${String(rec.data_preview).slice(0, 70)}`);
|
||
continue;
|
||
}
|
||
const mid = r?.data?.message_id;
|
||
sent[j.id] = mid;
|
||
await new Promise((r2) => setTimeout(r2, 5000));
|
||
const hasArrLabel = (e) => (Array.isArray(e.data.message) ? e.data.message : [])
|
||
.some((s) => s.type === 'json' && String(s.data?.data || '').includes('数组形'));
|
||
const hasMark = (e) => String(e.data.raw_message || '').includes('[QLf:' + j.id + ']');
|
||
const ev = events.find((e) => e.el >= t0 && (hasArrLabel(e) || hasMark(e)));
|
||
const jsonSeg = (Array.isArray(ev?.data?.message) ? ev.data.message : []).find((s) => s.type === 'json');
|
||
let detail = {};
|
||
try { detail = JSON.parse(jsonSeg.data.data)?.meta?.detail || {}; } catch {}
|
||
const rec = { id: j.id, desc: j.desc, retcode: r.__timeout ? 'TIMEOUT' : r.retcode,
|
||
message: r.message ?? r.wording ?? '', message_id: mid ?? null,
|
||
real_seq: ev?.data?.real_seq ?? null, tsum: detail.tsum ?? null,
|
||
news: JSON.stringify(detail.news ?? '').slice(0, 300), resid: detail.resid ?? null,
|
||
uniseq: detail.uniseq ?? null };
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'result', ...rec }) + '\n');
|
||
say(`${j.id.padEnd(22)} retcode=${String(rec.retcode).padEnd(6)} seq=${String(rec.real_seq ?? '-').padEnd(6)} tsum=${rec.tsum ?? '-'} news=${rec.news.slice(0, 110)}`);
|
||
}
|
||
|
||
// get_forward_msg 参数名穷举(只读)
|
||
say('\n--- get_forward_msg 参数穷举 ---');
|
||
const MID = sent.fwd_seg_parallel || 497853103;
|
||
const PARAM_SETS = [
|
||
{ message_id: MID },
|
||
{ message_id: String(MID) },
|
||
{ message_id: MID, group_id: GROUP },
|
||
{ id: String(MID) },
|
||
];
|
||
for (const p of PARAM_SETS) {
|
||
const r = await api('get_forward_msg', p);
|
||
const okFlag = r.retcode === 0;
|
||
say(`${JSON.stringify(p).slice(0, 60).padEnd(62)} retcode=${String(r.retcode).padEnd(6)} ${okFlag ? 'OK ' + JSON.stringify(r.data).slice(0, 120) : String(r.message).slice(0, 60)}`);
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'get_forward_msg', id: 'get_forward_msg',
|
||
retcode: r.retcode, message: r.message ?? '', params: p, resp: r }) + '\n');
|
||
}
|
||
|
||
// resid/uniseq 形式:从刚采到的事件里取
|
||
let resid = null, uniseq = null;
|
||
for (const e of events) {
|
||
const j = (e.data.message || []).find?.((s) => s.type === 'json');
|
||
if (!j) continue;
|
||
try {
|
||
const d = JSON.parse(j.data.data)?.meta?.detail || {};
|
||
if (d.resid) { resid = d.resid; uniseq = d.uniseq; break; }
|
||
} catch {}
|
||
}
|
||
if (resid) {
|
||
for (const p of [
|
||
{ resid, uniseq },
|
||
{ id: uniseq, resid },
|
||
{ message_id: MID, resid, uniseq, group_id: GROUP },
|
||
]) {
|
||
const r = await api('get_forward_msg', p);
|
||
say(`${'resid/uniseq:' + JSON.stringify(p).slice(0, 45).padEnd(50)} retcode=${String(r.retcode).padEnd(6)} ${r.retcode === 0 ? 'OK ' + JSON.stringify(r.data).slice(0, 120) : String(r.message).slice(0, 55)}`);
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'get_forward_msg', id: 'get_forward_msg',
|
||
retcode: r.retcode, message: r.message ?? '', params: p, resp: r }) + '\n');
|
||
}
|
||
} else say('未从事件里取到 resid,跳过 resid/uniseq 组合');
|
||
|
||
// 文件上传通知:延长等待,确认是否真的完全无通知事件
|
||
say('\n--- 群文件上传后的通知观测(等待 20s)---');
|
||
if (DO_WRITE) {
|
||
const t0 = Date.now();
|
||
const up = await api('upload_group_file', { group_id: GROUP,
|
||
file: 'base64://' + Buffer.from('QLinker 通知观测文件\n', 'utf8').toString('base64'),
|
||
name: `qlinker-notify-${stamp}.txt` });
|
||
say(`upload_group_file retcode=${up.retcode} ${String(up.message).slice(0, 60)}`);
|
||
fs.appendFileSync(OUT, JSON.stringify({ kind: 'upload', resp: up }) + '\n');
|
||
await new Promise((r) => setTimeout(r, 20000));
|
||
const during = events.filter((e) => e.el >= t0);
|
||
say(`20s 内收到事件 ${during.length} 条:` + (during.map((e) => e.data.notice_type || e.data.request_type || e.data.post_type).join(',') || '(无)'));
|
||
}
|
||
say('\n结果 -> ' + OUT);
|
||
try { ws.close(); } catch {}
|
||
process.exit(0);
|