feat: 发布热更 1.5.94,修复中转历史会话并支持一键清空
This commit is contained in:
@@ -964,6 +964,42 @@ async function deleteRow(id) {
|
||||
notify();
|
||||
}
|
||||
|
||||
async function clearAllSessions() {
|
||||
await ensureDb();
|
||||
const rows = all("SELECT id, cwd, rollout_path FROM sessions");
|
||||
const scopes = Array.from(new Set(rows.map((row) => row.cwd).filter(Boolean)));
|
||||
for (const row of rows) {
|
||||
deletedSessionIds.add(String(row.id || ""));
|
||||
if (row.rollout_path) {
|
||||
dirty.delete(row.rollout_path);
|
||||
seenRollouts.delete(row.rollout_path);
|
||||
}
|
||||
}
|
||||
queue.length = 0;
|
||||
const snapshot = Buffer.from(db.export());
|
||||
try {
|
||||
db.run("BEGIN");
|
||||
db.run("DELETE FROM sessions");
|
||||
// 保留 pinned=1 的长期身份/偏好事实;清掉由会话产生的普通决策与项目摘要。
|
||||
db.run("DELETE FROM core_decisions WHERE COALESCE(pinned,0)<>1");
|
||||
db.run("DELETE FROM core");
|
||||
db.run("COMMIT");
|
||||
flushDbStrict();
|
||||
} catch (e) {
|
||||
try { db.run("ROLLBACK"); } catch {}
|
||||
try { db.close(); } catch {}
|
||||
db = new SQLmod.Database(snapshot);
|
||||
throw e;
|
||||
}
|
||||
for (const scope of scopes) {
|
||||
try { fs.rmSync(archivePath(scope), { force: true }); } catch {}
|
||||
try { removeProjectCore(scope); } catch (e) { log("清空会话记忆块失败:" + (e.message || e)); }
|
||||
try { removeGeneratedHandoff(scope); } catch (e) { log("清空会话交接文件失败:" + (e.message || e)); }
|
||||
}
|
||||
notify();
|
||||
return { count: rows.length, scopes: scopes.length };
|
||||
}
|
||||
|
||||
async function deleteSession(id, cwd) {
|
||||
deletedSessionIds.add(String(id || ""));
|
||||
await ensureDb();
|
||||
@@ -1019,6 +1055,7 @@ module.exports = {
|
||||
resummarize,
|
||||
deleteRow,
|
||||
deleteSession,
|
||||
clearAllSessions,
|
||||
handoffPath,
|
||||
renderProjectCore,
|
||||
writeProjectCore,
|
||||
|
||||
Reference in New Issue
Block a user