openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
113 lines (112 loc) • 5.13 kB
JavaScript
import { o as writeRuntimeJson, r as defaultRuntime, t as ExitError } from "./runtime-B-SLYP-m.mjs";
import { m as readSourceConfigBestEffort, s as readConfigFileSnapshot } from "./io.runtime-DsJ2dLCQ.mjs";
import "./io-4QsrsWTJ.mjs";
import { n as formatDurationHuman } from "./format-duration-iMnO_MN6.mjs";
import { r as formatCliJsonFailure } from "./failure-output-DVVDqwuu.mjs";
import { n as collectUpdateCleanupInventory, r as inspectSessionSqliteRecovery } from "./doctor-session-sqlite-recovery-inventory-nxlj5kaN.mjs";
import { i as selectUnmanifestedRecovery, n as retireSessionSqliteRecovery } from "./doctor-session-sqlite-retirement-prAcoVwY.mjs";
import { t as updateMaintenanceError } from "./update-maintenance-error-kAWA0Ugw.mjs";
import { confirm } from "@clack/prompts";
//#region src/cli/update-cli/cleanup.ts
/** Local recovery retirement. This handler never invokes update or Doctor repair. */
function renderCleanup(e) {
defaultRuntime.log(`Recovery cleanup: ${e.stateDir}`);
if (e.missingOriginals > 0) defaultRuntime.log(`Missing recovery originals: ${e.missingOriginals} (historical receipts retained; no bytes on disk).`);
for (const t of e.artifacts) {
const e = t.modifiedAt ? `; modified ${formatDurationHuman(Math.max(0, Date.now() - Date.parse(t.modifiedAt)))} ago` : "";
defaultRuntime.log(` ${t.outcome}: ${t.path} (${t.bytes} bytes${e}; ${t.reason})${t.detail ? ` ${t.detail}` : ""}`);
if (t.consequence && t.outcome === "candidate") defaultRuntime.log(` ${t.consequence}`);
}
defaultRuntime.log(`Candidates: ${e.totals.candidateBytes} bytes; verification required: ${e.totals.verificationRequiredBytes}; protected: ${e.totals.protectedBytes}; blocked: ${e.totals.blockedBytes}.`);
const t = e.artifacts.filter((e) => e.kind === "update-capture");
if (t.length > 0) {
const sum = (e) => t.filter((t) => e === void 0 || t.outcome === e).reduce((e, t) => e + t.bytes, 0);
defaultRuntime.log(`Update captures: ${t.length} (${sum()} bytes); candidates: ${sum("candidate")} bytes; protected: ${sum("protected")} bytes.`);
}
defaultRuntime.log("Retiring originals permanently loses rollback, including pre-repair branches and metadata. Logical bytes are not a promise of physical space reclaimed.");
if (e.artifacts.length === 0) defaultRuntime.log("No recorded recovery artifacts found.");
if (e.status === "complete") defaultRuntime.log(`Removed ${e.totals.removedFiles} files (${e.totals.removedBytes} logical bytes).`);
}
async function updateCleanupCommand(e) {
let t;
try {
const n = e.includeUnmanifested?.length ? async () => {
const e = await readConfigFileSnapshot({
observe: false,
pluginValidation: "core-only"
});
if (!e.valid) throw new Error("Cannot include unmanifested recovery: configuration and includes must resolve successfully before selection or removal.");
return e.sourceConfig;
} : readSourceConfigBestEffort;
const r = await n();
if (e.includeUnmanifested?.length) {
const n = collectUpdateCleanupInventory({
cfg: r,
env: process.env
});
selectUnmanifestedRecovery({
inventory: n,
cfg: r,
env: process.env,
paths: e.includeUnmanifested
});
t = n.report;
} else t = inspectSessionSqliteRecovery({
cfg: r,
env: process.env
});
if (!e.dryRun) {
if (t.artifacts.length === 0 && !e.yes) t.status = "complete";
else if (!e.yes && (e.json || !process.stdin.isTTY || !process.stderr.isTTY)) t.status = "refused";
else t = await retireSessionSqliteRecovery({
env: process.env,
preview: t,
includeUnmanifested: e.includeUnmanifested,
readConfig: n,
onProgress: ({ phase: e, path: t, index: n, total: r, bytes: i }) => {
const a = {
verifying: "Verifying original",
claiming: "Retiring original",
"removing-capture": "Removing capture",
"removing-unmanifested": "Retiring explicitly selected original"
}[e];
process.stderr.write(`${a} ${n}/${r}: ${t} (${i} bytes)\n`);
},
confirm: async (t) => {
if (e.yes || t.artifacts.length === 0) return true;
renderCleanup(t);
return await confirm({
message: "Permanently retire these rollback originals?",
initialValue: false,
output: process.stderr
}) === true;
}
});
}
if (e.json) writeRuntimeJson(defaultRuntime, {
...t,
artifacts: t.artifacts.map((e) => e.modifiedAt ? {
...e,
ageMs: Math.max(0, Date.now() - Date.parse(e.modifiedAt))
} : e),
dryRun: e.dryRun === true
});
else renderCleanup(t);
if (t.status === "refused") {
defaultRuntime.error("Nothing removed. Review with `openclaw update cleanup --dry-run`; use --yes to acknowledge permanent rollback loss.");
defaultRuntime.exit(1);
} else if (t.status === "blocked") defaultRuntime.exit(1);
} catch (n) {
if (n instanceof ExitError) throw n;
const r = String(updateMaintenanceError(n));
if (e.json) writeRuntimeJson(defaultRuntime, {
...t,
...formatCliJsonFailure(r),
status: "blocked"
});
else defaultRuntime.error(r);
defaultRuntime.exit(1);
}
}
//#endregion
export { updateCleanupCommand };