Files
writing-agent/tools/st-request-diff/account-entries.mjs
T
chenmoranzhi 1a5ef3b2bc 抓包对比工具补一批一次性脚本:拆预设、对请求、跑 A/B 与拒答抽样。
这些脚本都是我对着酒馆真实请求手工核对用的,留在仓库里方便下次重跑;跑出来的本地数据目录含接口 key,已经写进忽略规则。
2026-10-26 01:09:56 +08:00

49 lines
2.4 KiB
JavaScript

// 逐条盘点:预设里的每个 prompt 条目,最终有没有进到两边的请求体里。
// 用法: node account-entries.mjs <preset.json> <st-capture.json> <wa-capture.json>
import { readFileSync } from "node:fs";
const preset = JSON.parse(readFileSync(process.argv[2], "utf8"));
const readSide = (f) => {
const outer = JSON.parse(readFileSync(f, "utf8"));
const body = JSON.parse(outer.body);
return body.messages.map((m) => String(m.content ?? "")).join("\n");
};
const norm = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
const stAll = norm(readSide(process.argv[3]));
const waAll = norm(readSide(process.argv[4]));
function candidates(content) {
const t = norm(content);
if (t.length < 20) return [t];
const out = [t.slice(0, 120), t.slice(Math.floor(t.length / 2), Math.floor(t.length / 2) + 120), t.slice(-120)];
return out.map((x) => norm(x)).filter((x) => x.length >= 12);
}
const hit = (pool, content) => candidates(content).some((c) => pool.includes(c));
console.log("=== prompt_order 块 ===");
for (const b of preset.prompt_order || []) {
const on = (b.order || []).filter((o) => o.enabled !== false).length;
console.log("character_id=" + b.character_id + " 条目=" + (b.order || []).length + " 开着=" + on);
}
const block = (preset.prompt_order || []).find((b) => b.character_id === 100001) || (preset.prompt_order || [])[0] || { order: [] };
const orderEnabled = new Map((block.order || []).map((o) => [o.identifier, o.enabled !== false]));
console.log("\n条目名 | 字数 | order开 | prompt开 | role | 酒馆 | 本仓库");
let inSt = 0, inWa = 0, both = 0, onlyWa = 0, onlySt = 0;
for (const p of preset.prompts || []) {
const content = String(p.content ?? "");
if (!content.trim()) continue;
const hs = hit(stAll, content);
const hw = hit(waAll, content);
if (hs) inSt++;
if (hw) inWa++;
if (hs && hw) both++;
if (hs && !hw) onlySt++;
if (!hs && hw) onlyWa++;
const flag = hs === hw ? "" : " <<<";
console.log(
String(p.name || p.identifier).slice(0, 38) + " | " + content.length + " | " + (orderEnabled.get(p.identifier) ? "开" : "关") + " | " + (p.enabled === false ? "关" : "开") + " | " + (p.role || "system") + " | " + (hs ? "有" : "—") + " | " + (hw ? "有" : "—") + flag,
);
}
console.log("\n合计 酒馆 " + inSt + " / 本仓库 " + inWa + ",两边都有 " + both + ",只有酒馆 " + onlySt + ",只有本仓库 " + onlyWa);