Files
writing-agent/tools/st-request-diff/preset-accounting.mjs
T
chenmoranzhi 9dc927282f 预设兼容:按真实抓包对齐装配与包装层,补上声明式工具与预设正则。
- 装配只认 prompt_order.enabled;squash_system_messages 只合并相邻 system(新增 system 档,连接符按酒馆用单换行)
- 包装层:new_chat_prompt、示例对话(new_example_chat_prompt + <START> 切段 + name)、角色卡三块与 personality_format/scenario_format、{{user}}/{{char}} 取值、任务契约并进预设条目
- 工具协议:按 ToolBindings / 伪工具协议数据声明真 tools(presetToolPolicy=preset),工具描述用到的条目不再重复作为消息发出
- 正则:promptOnly 作用于对话历史(含 depth 过滤)、写入时脚本改写回复;{{//}} 注释按配平扫描
- tools/st-request-diff:真假上游抓包对比工具、三份预设的机制结论与实测报告
2026-10-23 00:13:08 +08:00

32 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 一个预设到底有多少内容、哪些进了请求:启用条目正文总量 / 最大条目 / 会改请求的正则。
// 用法: node node_modules/tsx/dist/cli.mjs tools/st-request-diff/preset-accounting.mjs <preset.json>
import { readFileSync } from "node:fs";
import path from "node:path";
import { importSillyTavernPreset } from "../../src/preset/importer.js";
import { buildPresetDiagnostics } from "../../src/preset/diagnostics.js";
const file = process.argv[2];
const raw = JSON.parse(readFileSync(file, "utf8"));
const report = importSillyTavernPreset(raw, { name: path.basename(file, ".json") });
const preset = report.preset;
const orderEnabled = new Map(preset.promptOrder.map((o) => [o.promptId, o.enabled]));
const entries = preset.prompts
.filter((p) => orderEnabled.get(p.id) === true)
.map((p) => ({ id: p.id, name: p.name, marker: p.marker, len: p.content.length }))
.sort((a, b) => b.len - a.len);
const total = entries.reduce((n, e) => n + e.len, 0);
console.log("=== " + path.basename(file) + ":order 启用条目 " + entries.length + " 条,正文合计 " + total + " 字");
console.log(" 最大的 8 条:");
for (const entry of entries.slice(0, 8)) {
console.log(" " + String(entry.len).padStart(6) + " 字 " + (entry.marker ? "[洞] " : "") + entry.name + " (" + entry.id.slice(0, 12) + ")");
}
const diagnostics = buildPresetDiagnostics(preset, preset.raw);
const promptRegexes = diagnostics.regexes.filter((r) => r.promptOnly || r.markdownOnly === false);
console.log("=== 正则 " + diagnostics.regexes.length + " 条,其中 promptOnly=" + diagnostics.regexes.filter((r) => r.promptOnly).length + " 条,会影响发出的请求");
for (const regex of diagnostics.regexes.slice(0, 8)) {
console.log(" " + regex.name + " placement=" + JSON.stringify(regex.placement) + " promptOnly=" + regex.promptOnly + " markdownOnly=" + regex.markdownOnly + " disabled=" + regex.disabled);
}
console.log("=== 脚本 " + diagnostics.scripts.length + " 个:" + diagnostics.scripts.map((s) => s.name + "(" + Math.round(s.bytes / 1024) + "KB" + (s.isUiPanel ? ",界面" : "") + ")").join("、"));
console.log("=== 工具协议 bindings=" + diagnostics.toolProtocol.bindings.length + " entries=" + diagnostics.toolProtocol.entries.length + " placeholders=" + diagnostics.toolProtocol.placeholders.length);