fix: remove retired LivingMemory panel actions

这个提交存在于:
YokiiroBW 2026-07-27 12:25:37 +08:00
父节点 600b07e15c
当前提交 c9106d9014
共有 4 个文件被更改,包括 22 次插入 和 192 次删除

查看文件

@ -240,3 +240,13 @@
- 修复或规避:新增 `tests/test_m6_r2_real_dto_shape.py`——优先 import 陪伴仓真实的 `build_bot_personal_dto` 产出信封,拿不到时退回逐字复刻样本,两条路径 body 里都没有 date;补齐 R1 漏测的 `bot_calendar_event`,并用集合断言把覆盖范围钉在 `BOT_PERSONAL_TYPE_CONTRACTS` 减严格五类上。`_FORBIDDEN_VALUE_PATTERNS` 由 4 条增至 8 条(保留原前缀模式,新增中缀路径 / `base64,` / `data:` URI / `-----begin `)。date 校验一字未改,`date=""`、`2026-13-45`、naive `occurred_at` 三条负例钉死。
- 预防规则:跨插件兼容回归必须包含调用方真实序列化输出样本,禁止只用提供方自造夹具;值级敏感检测一律按中缀设计并配反例防误杀;「覆盖了哪几类」要用集合断言钉住,不能靠人肉核对。
- 验证证据:新增 45 项通过;记忆侧总计 243 项通过;`compileall` 通过;无新增错误码(全部复用 `privacy_rejected`,capability 25 码不变);联合 E2E 90 项全通过、非五类 7/7;实施验收由 `REOPEN_REQUIRED` 转 `LOCAL_ACCEPTED`。
## 2026-07-27 — 后端退役必须同步清除面板请求与断言
- 阶段:LivingMemory 退役残留修复
- 类型:API契约 / 功能行为 / 测试
- 现象:后端已删除 LivingMemory 迁移、导入和修复路由,但记忆面板仍展示三个按钮并请求旧接口;回归测试反向要求这些旧入口存在。
- 根因:退役改动没有将静态 HTML、前端请求、结果渲染和前端回归断言作为同一契约面清理。
- 修复或规避:删除面板入口、请求函数、结果渲染、配置指南和旧来源提示;保留插件冲突检测与通用维护、可移植 JSONL 导入。
- 预防规则:删除或替换后端能力时,必须同批核对实现、路由、配置、HTML、JS、测试和文档;测试应保护目标状态,不应保护被退役的入口。
- 验证证据:`python -m unittest tests.test_panel_regressions` 9/9 通过;`node --check pages/记忆面板/app.js` 通过;面板源码无 `LivingMemory`、旧路径或旧按钮 ID。

查看文件

@ -81,7 +81,6 @@ const CONFIG_ADVANCED_FALLBACKS = {
"config:conversation_memory_advanced": "config:conversation_memory",
"config:context_orchestration_advanced": "config:context_orchestration",
"config:maintenance_decay": "config:maintenance",
"config:livingmemory_migration": "maintenance",
migration: "maintenance",
clear: "maintenance",
};
@ -142,11 +141,6 @@ const CONFIG_MODULE_GUIDES = {
tune: "搜索人物/话题时漏召回可开启图谱一跳扩展;召回过宽时降低扩展上限。",
avoid: "图谱扩展不会绕过权限,不要把它当权限共享开关。",
},
livingmemory_migration: {
purpose: "控制 LivingMemory 旧库导入路径和单次导入上限。",
tune: "迁移前先预览;旧库很大时分批导入并观察跳过原因。",
avoid: "不要直接复制旧 SQLite 覆盖当前数据库。",
},
maintenance: {
purpose: "控制备份、原始事件保留和长期旧记忆自然衰减。",
tune: "数据库增长快时调整原始事件保留;旧碎片太多时开启自然衰减并设置合理阈值。",
@ -4142,7 +4136,6 @@ async function showMemory(id) {
<span class="badge gold">${escapeHtml(memory.lifecycle)}</span>
</div>
</div>
${memory.source_plugin === "livingmemory" && isNumericOnlyContent(memory.content) ? `<div class="empty-state error-state"><b>导入内容未修复</b><span>这条记录目前只有旧库编号,请先在维护工具中执行“修复 LivingMemory 内容”。</span></div>` : ""}
${renderMemoryStructuredMetadata(memory)}
<form id="memoryManageForm" class="memory-manage-form" autocomplete="off">
<label>
@ -4423,20 +4416,6 @@ function clearDetail() {
`;
}
function livingMemoryPathValue() {
const activeInputs = Array.from(document.querySelectorAll("#view-archive .archive-section.is-active .livingmemory-path"));
const filled = activeInputs.find((input) => input.value.trim());
if (filled) return filled.value.trim();
const fallbackInput = activeInputs[0] || $("#view-archive .livingmemory-path");
return fallbackInput?.value.trim() || "";
}
function sumLivingMemoryRows(tables = [], importable = true) {
return tables
.filter((table) => Boolean(table.importable) === importable)
.reduce((total, table) => total + Math.max(0, Number(table.count) || 0), 0);
}
function archiveResultCard(label, value, note = "", tone = "blue") {
return `
<article class="archive-result-card">
@ -4456,109 +4435,6 @@ function renderArchiveResultDetails(value) {
`;
}
function renderLivingMemoryPreview(report = {}) {
const candidates = Array.isArray(report.candidates) ? report.candidates : [];
if (!candidates.length) {
return `
<section class="archive-result-panel">
<div class="archive-result-head">
<b>未找到 LivingMemory 数据库</b>
<span>可以填写数据库路径后重新预览。</span>
</div>
${renderArchiveResultDetails(report)}
</section>
`;
}
const primary = candidates[0] || {};
const tables = Array.isArray(primary.tables) ? primary.tables : [];
const importableRows = sumLivingMemoryRows(tables, true);
const skippedRows = sumLivingMemoryRows(tables, false);
const importableTables = tables.filter((table) => table.importable);
const skippedTables = tables.filter((table) => !table.importable);
return `
<section class="archive-result-panel">
<div class="archive-result-head">
<b>LivingMemory 预览</b>
<span>${escapeHtml(primary.path || "未记录来源路径")}</span>
</div>
<div class="archive-result-grid">
${archiveResultCard("可导入", `${importableRows} 条`, `${importableTables.length} 张表`, "teal")}
${archiveResultCard("将跳过", `${skippedRows} 条`, "派生碎片或空表", "gold")}
${archiveResultCard("候选库", `${candidates.length} 个`, candidates.length > 1 ? "默认导入第一项" : "已锁定来源", "blue")}
</div>
${importableTables.length ? `
<div class="archive-table-list">
<b>将导入的表</b>
${importableTables.slice(0, 6).map((table) => `
<span><strong>${escapeHtml(table.name || "-")}</strong><em>${escapeHtml(table.count || 0)} 行</em></span>
`).join("")}
</div>
` : `<div class="empty-state">没有可导入的完整摘要表。</div>`}
${skippedTables.length ? `
<div class="archive-table-list is-muted">
<b>跳过的碎片</b>
${skippedTables.slice(0, 6).map((table) => `
<span><strong>${escapeHtml(table.name || "-")}</strong><em>${escapeHtml(table.note || "not_importable")}</em></span>
`).join("")}
</div>
` : ""}
${renderArchiveResultDetails(report)}
</section>
`;
}
function renderLivingMemoryImportResult(result = {}) {
if (result.reason && !result.source_path) {
return `
<section class="archive-result-panel">
<div class="archive-result-head">
<b>导入未执行</b>
<span>${escapeHtml(result.reason)}</span>
</div>
${renderArchiveResultDetails(result)}
</section>
`;
}
return `
<section class="archive-result-panel">
<div class="archive-result-head">
<b>LivingMemory 导入完成</b>
<span>${escapeHtml(result.source_path || "未记录来源路径")}</span>
</div>
<div class="archive-result-grid">
${archiveResultCard("已导入", `${result.imported || 0} 条`, result.batch_id ? `批次 ${shortId(result.batch_id)}` : "", "teal")}
${archiveResultCard("异常跳过", `${result.skipped || 0} 条`, "空内容或无法识别", Number(result.skipped || 0) ? "gold" : "blue")}
${archiveResultCard("审核状态", `${result.default_review_status || "auto"}`, "导入策略", "violet")}
</div>
${Array.isArray(result.importable_tables) && result.importable_tables.length ? `
<div class="archive-table-list">
<b>导入明细</b>
${result.importable_tables.slice(0, 8).map((table) => `
<span><strong>${escapeHtml(table.name || "-")}</strong><em>${escapeHtml(table.imported || 0)} / ${escapeHtml(table.count || 0)}</em></span>
`).join("")}
</div>
` : ""}
${renderArchiveResultDetails(result)}
</section>
`;
}
function renderLivingMemoryRepairResult(result = {}) {
return `
<section class="archive-result-panel">
<div class="archive-result-head">
<b>内容修复结果</b>
<span>${escapeHtml(result.source_path || result.reason || "未记录来源路径")}</span>
</div>
<div class="archive-result-grid">
${archiveResultCard("已修复", `${result.updated || 0} 条`, "旧编号内容已替换", "teal")}
${archiveResultCard("跳过", `${result.skipped || 0} 条`, result.error || "没有匹配内容", Number(result.skipped || 0) ? "gold" : "blue")}
</div>
${renderArchiveResultDetails(result)}
</section>
`;
}
function renderGenericArchiveResult(value = {}, title = "执行结果") {
const entries = Object.entries(value || {}).filter(([, item]) => typeof item !== "object");
return `
@ -4581,15 +4457,7 @@ function showArchiveResult(value, kind = "generic", host = "#importResult") {
const box = typeof host === "string" ? $(host) : host;
if (!box) return;
box.hidden = false;
if (kind === "preview") {
box.innerHTML = renderLivingMemoryPreview(value);
} else if (kind === "import") {
box.innerHTML = renderLivingMemoryImportResult(value);
} else if (kind === "repair") {
box.innerHTML = renderLivingMemoryRepairResult(value);
} else {
box.innerHTML = renderGenericArchiveResult(value, kind === "maintenance" ? "维护结果" : "执行结果");
}
box.innerHTML = renderGenericArchiveResult(value, kind === "maintenance" ? "维护结果" : "执行结果");
}
function showInlineConfirmation({
@ -5567,13 +5435,6 @@ async function rollbackHistoricalChatImport() {
showToast("历史对话导入已回滚");
}
async function repairLivingMemoryContent() {
const path = livingMemoryPathValue();
const data = await apiPost("/maintenance/repair_livingmemory_content", { path });
await refreshAll();
showArchiveResult(data.result, "repair");
showToast(`已修复 ${data.result?.updated || 0} 条 LivingMemory 内容`);
}
async function clearAllMemoryData() {
const box = $("#importResult");
@ -5738,35 +5599,6 @@ async function clearCurrentScopedMemory(scope) {
showScopedClearConfirm(payload, counts);
}
async function previewImport() {
const path = livingMemoryPathValue();
const params = new URLSearchParams();
if (path) params.set("path", path);
const data = await apiGet(`/import/livingmemory/preview?${params.toString()}`);
showArchiveResult(data.report, "preview");
showToast("预览已生成");
}
async function runImport() {
const path = livingMemoryPathValue();
showInlineConfirmation({
host: "#importResult",
title: "导入 LivingMemory",
message: path
? `将从 ${path} 导入完整摘要,跳过派生碎片;执行前会自动备份当前数据库。`
: "将从自动发现的 LivingMemory 数据库导入完整摘要,跳过派生碎片;执行前会自动备份当前数据库。",
confirmLabel: "执行导入",
busyText: "正在导入 LivingMemory...",
onConfirm: () => executeLivingMemoryImport(path),
});
}
async function executeLivingMemoryImport(path) {
const data = await apiPost("/import/livingmemory/run", { path });
await refreshAll();
showArchiveResult(data.result, "import");
showToast("导入已完成");
}
async function refreshAll() {
await loadCompanionAvailability();
@ -5925,13 +5757,10 @@ function bindActions() {
$("#historicalChatFile")?.click();
}
});
$("#repairLivingMemoryBtn").addEventListener("click", () => withBusy("正在修复 LivingMemory 内容...", repairLivingMemoryContent));
$("#clearAllMemoryBtn").addEventListener("click", clearAllMemoryData);
$("#clearCurrentGroupMemoryBtn")?.addEventListener("click", () => withBusy("正在预览范围清理...", () => clearCurrentScopedMemory("group")));
$("#clearGroupMemberMemoryBtn")?.addEventListener("click", () => withBusy("正在预览群成员记忆清理...", () => clearCurrentScopedMemory("group_member")));
$("#clearCurrentPrivateMemoryBtn")?.addEventListener("click", () => withBusy("正在预览范围清理...", () => clearCurrentScopedMemory("private")));
$("#previewImportBtn").addEventListener("click", () => withBusy("正在扫描 LivingMemory...", previewImport));
$("#runImportBtn").addEventListener("click", () => withBusy("正在导入 LivingMemory...", runImport));
$("#globalSearch").addEventListener("keydown", (event) => {
if (event.key === "Enter") loadActiveView();
});

查看文件

@ -261,7 +261,7 @@
<section id="view-archive" class="view">
<div class="section-head">
<h3>维护 / 迁移 / 配置</h3>
<p>执行维护、LivingMemory 迁移、清理和导入修复。</p>
<p>执行维护、可移植数据导入、清理和导入修复。</p>
</div>
<div class="archive-grid">
<section class="archive-section" data-archive-section="retrieval">
@ -298,27 +298,12 @@
</div>
</section>
<section class="maintenance-action">
<b>4. LivingMemory 导入</b>
<p class="archive-note">先预览可导入数量和跳过原因,再执行导入。当前策略只导入完整摘要,跳过派生碎片。</p>
<input class="livingmemory-path" type="text" placeholder="LivingMemory 数据库路径,可留空自动扫描" />
<div class="inline-actions">
<button id="previewImportBtn" type="button">预览导入</button>
<button id="runImportBtn" type="button">执行导入</button>
</div>
</section>
<section class="maintenance-action">
<b>5. 内容修复</b>
<p class="archive-note">用于修复早期导入后只剩旧库编号的记忆。建议先确认 LivingMemory 数据库路径,再执行修复。</p>
<input class="livingmemory-path" type="text" placeholder="LivingMemory 数据库路径,可留空自动扫描" />
<button id="repairLivingMemoryBtn" type="button">修复 LivingMemory 内容</button>
</section>
<section class="maintenance-action">
<b>6. 维护检查</b>
<b>4. 维护检查</b>
<p class="archive-note">修复索引、刷新统计并整理数据库状态。适合导入、清理或配置调整后手动执行一次。</p>
<button id="maintenanceBtn" type="button">运行维护</button>
</section>
<section class="maintenance-action">
<b>7. 危险清理</b>
<b>5. 危险清理</b>
<p class="archive-note">清空会先备份数据库,再删除记忆、权限规则、时间线、关系、身份、注入日志和导入批次。</p>
<button id="clearAllMemoryBtn" class="danger" type="button">清空全部记忆</button>
</section>

查看文件

@ -11,11 +11,17 @@ ROOT = Path(__file__).resolve().parents[1]
class PanelRegressionTests(unittest.TestCase):
def test_webview_actions_do_not_depend_on_native_dialogs(self) -> None:
script = (ROOT / "pages" / "记忆面板" / "app.js").read_text(encoding="utf-8")
page = (ROOT / "pages" / "记忆面板" / "index.html").read_text(encoding="utf-8")
self.assertIsNone(re.search(r"\b(?:confirm|alert|prompt)\s*\(", script))
self.assertIn("function showInlineConfirmation", script)
self.assertIn('title: "导入 LivingMemory"', script)
self.assertIn("executeLivingMemoryImport", script)
self.assertNotIn("LivingMemory", script)
self.assertNotIn("livingmemory", script.lower())
self.assertNotIn("LivingMemory", page)
self.assertNotIn("livingmemory-path", page)
self.assertNotIn('id="previewImportBtn"', page)
self.assertNotIn('id="runImportBtn"', page)
self.assertNotIn('id="repairLivingMemoryBtn"', page)
def test_personal_memory_failures_are_visible_and_recoverable(self) -> None:
script = (ROOT / "pages" / "记忆面板" / "app.js").read_text(encoding="utf-8")