UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.13 kB
import"./src-0ci69Prg.mjs";import{n as formatByteSize}from"./format-66SdinIu.mjs";import{n as resolveOpenClawPackageRoot}from"./openclaw-root-DP80HYD2.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{n as quotePowerShellArg}from"./quote-cli-arg-BUHoGELl.mjs";import{i as resolveNpmGlobalPrefixLayoutFromGlobalRoot}from"./update-npm-prefix-PBytTD1i.mjs";import{f as isUpdateDoctorLintPass}from"./update-phase-CCaxuca0.mjs";import path from"node:path";import fs from"node:fs/promises"; //!src/commands/doctor-update-snapshots.ts const SNAPSHOT_NAME=/^\.openclaw[.-]package-backup-.*\.databases$/u;const MAX_ROOT_ENTRIES=1024;const MAX_SIZE_ENTRIES=4096;const MAX_DEPTH=32;const SCAN_BUDGET_MS=200;async function collectUpdateSnapshotHealthFindings(e=process.env){if(isUpdateDoctorLintPass(e))return[];const t=await resolveOpenClawPackageRoot({moduleUrl:import.meta.url,argv1:process.argv[1]});const n=t?resolveNpmGlobalPrefixLayoutFromGlobalRoot(path.dirname(t)):null;if(!n)return[];const r=performance.now()+SCAN_BUDGET_MS;const i=[];let a=false;let o=0;try{const e=await fs.opendir(n.globalRoot);for await(const t of e){if(++o>MAX_ROOT_ENTRIES||performance.now()>r){a=true;break}if(t.isDirectory()&&SNAPSHOT_NAME.test(t.name))i.push(path.join(n.globalRoot,t.name))}}catch(e){if(hasErrnoCode(e,`ENOENT`))return[];a=true}if(i.length===0)return a?[{checkId:`core/doctor/update-snapshots`,severity:`warning`,message:`Inspection was incomplete; retained pre-migration database snapshots may remain. Manually list the npm global root ${n.globalRoot}, including hidden entries, and check for .openclaw.package-backup-*.databases and .openclaw-package-backup-*.databases directories.`}]:[];i.sort();let s=0;let c=0;const l=i.map(e=>({directory:e,depth:0}));while(l.length>0){if(c>=MAX_SIZE_ENTRIES||performance.now()>r){a=true;break}const e=l.pop();try{if(!(await fs.lstat(e.directory)).isDirectory()){a=true;continue}const t=await fs.opendir(e.directory);for await(const n of t){if(++c>MAX_SIZE_ENTRIES||performance.now()>r){a=true;break}const t=path.join(e.directory,n.name);if(n.isDirectory()){if(e.depth<MAX_DEPTH)l.push({directory:t,depth:e.depth+1});else a=true}else if(n.isFile()){const e=await fs.lstat(t);if(e.isFile())s+=e.size}}}catch{a=true}}const u=formatByteSize(s,{style:`iec`,maxUnit:`tera`,separator:` `,fractionDigits:1});const d=i.map(e=>process.platform===`win32`?`Remove-Item -LiteralPath ${quotePowerShellArg(e)} -Recurse -Force`:`rm -rf -- '${e.replaceAll(`'`,`'\\''`)}'`);return[{checkId:`core/doctor/update-snapshots`,severity:`warning`,message:[`${a?`At least `:``}${i.length} retained pre-migration database snapshot director${i.length===1?`y`:`ies`}: ${a?`at least `:``}${s} bytes (${u}) in regular files.`,...a?[`Inspection was bounded or incomplete; paths and size may be partial.`]:[],`Doctor cannot prove these updates succeeded and never removes these snapshots, including with --fix.`,`Before manual removal, confirm no update is in progress and no recovery needs these snapshots; inspect the corresponding update reports first.`,...d].join(` `)}]}export{collectUpdateSnapshotHealthFindings};