UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

59 lines (58 loc) • 2.83 kB
import { c as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-CmKkMYdo.mjs"; import { a as resolveSqliteDatabaseFilePaths } from "./sqlite-files-D1rDNZzV.mjs"; import { x as assertOpenClawStateDatabaseForMaintenance } from "./openclaw-state-db-fast-path-Kg79WElU.mjs"; import { r as clearOpenClawDatabaseQuarantine } from "./openclaw-quarantine-store-CUJxC7wy.mjs"; import { a as clearOpenClawStateDatabaseOpenFailure, f as isOpenClawStateDatabaseOpen } from "./openclaw-state-db-cache-CmYLFRSt.mjs"; import { n as assertOpenClawStateWriteAllowed } from "./openclaw-state-ownership-C6zxQPsi.mjs"; import { y as ensureOpenClawStatePermissions } from "./openclaw-state-db-DJZ7EKoI.mjs"; import { i as withDoctorSqliteMaintenanceLock } from "./doctor-sqlite-maintenance-lock-Bbm5GClb.mjs"; import { n as compactDoctorSqliteFile } from "./doctor-sqlite-compact-DrT7syfW.mjs"; import fs from "node:fs"; //#region src/commands/doctor-state-sqlite-compact.ts /** Explicit doctor maintenance for the canonical shared state SQLite database. */ /** Compact only the canonical shared state database resolved for this invocation. */ async function runDoctorStateSqliteCompact(options = {}) { const env = options.env ?? process.env; const sqlitePath = resolveOpenClawStateSqlitePath(env); const stat = fs.lstatSync(sqlitePath, { throwIfNoEntry: false }); if (!stat) return { mode: "compact", path: sqlitePath, reason: "missing", skipped: true }; if (!stat.isFile()) throw new Error(`Canonical OpenClaw state database is not a regular file: ${sqlitePath}`); return await withDoctorSqliteMaintenanceLock({ env, operation: "state SQLite compaction", protectedPaths: resolveSqliteDatabaseFilePaths(sqlitePath), run: (authority) => { authority.assertCurrent(); if (isOpenClawStateDatabaseOpen()) throw new Error("The shared OpenClaw state database is already open in this process. Stop OpenClaw and retry."); return { ...compactDoctorSqliteFile({ afterSuccess: () => { if (!clearOpenClawDatabaseQuarantine(sqlitePath, { env })) throw new Error(`OpenClaw state database ${sqlitePath} was compacted, but its persisted quarantine record could not be cleared. Rerun openclaw doctor --fix so the database is not refused again.`); clearOpenClawStateDatabaseOpenFailure(sqlitePath); ensureOpenClawStatePermissions(sqlitePath, env); }, sqlitePath, validateBeforeMutation: (database) => { authority.assertCurrent(); assertOpenClawStateWriteAllowed({ database, databasePath: sqlitePath, env }); assertOpenClawStateDatabaseForMaintenance(database, { pathname: sqlitePath }); } }), mode: "compact", path: sqlitePath, skipped: false }; } }); } //#endregion export { runDoctorStateSqliteCompact };