openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 3.41 kB
JavaScript
import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import path from"node:path";import fs from"node:fs/promises";
//!src/infra/backup-audit-paths.ts
const LEGACY_AUDIT_PATHS=[{directory:`logs`,basename:`config-audit.jsonl`},{directory:`audit`,basename:`system-agent.jsonl`},{directory:`audit`,basename:`crestodian.jsonl`}].map(({directory:e,basename:t})=>{const n=t.replace(/[.*+?^${}()|[\]\\]/gu,`\\$&`);return{directory:e,pattern:new RegExp(`^(?:${n}|\\.${n}\\.doctor-importing(?:\\.(?:[2-9]|[1-9][0-9]+))?|${n}\\.migrated(?:\\.(?:[2-9]|[1-9][0-9]+))?\\.raw(?:\\.doctor-scrub-(?:progress|restore|staging))?)$`,`u`)}});function isLegacyAuditMigrationBackupPath(e,t){const n=path.relative(path.resolve(t),path.resolve(e));if(!n||n.startsWith(`..${path.sep}`)||path.isAbsolute(n))return false;const r=path.dirname(n);const i=path.basename(n);const a=i.indexOf(`.quarantined-`);const o=a<0?i:i.slice(0,a);return LEGACY_AUDIT_PATHS.some(e=>r===e.directory&&e.pattern.test(o))}async function hasLegacyAuditBackupSources(e){for(const{directory:t}of LEGACY_AUDIT_PATHS){let n;const r=path.join(e,t);try{n=await fs.readdir(r)}catch(e){if(hasErrnoCode(e,`ENOENT`))continue;throw e}if(n.some(t=>isLegacyAuditMigrationBackupPath(path.join(r,t),e)))return true}return false}
//!src/infra/backup-volatile-filter.ts
const CHROMIUM_SINGLETON_FILES=/* @__PURE__ */ new Set([`SingletonCookie`,`SingletonLock`,`SingletonSocket`]);const VOLATILE_DIRECTORY_RULES=[[[`sandbox/skills-workspaces`,`cache/control-ui-assets`,`tmp/plugin-captures`],void 0],[[`sessions`,`cron/runs`,`logs`],[`.jsonl`,`.log`]],[[`delivery-queue`,`session-delivery-queue`],[`.json`,`.delivered`,`.tmp`]]];const SQLITE_MEMORY_TRANSIENT_PATH_PATTERN=/(?:^|\/)(?:[^/]+\.sqlite\.(?:generation-(?:lock|writer)|reindex-lock)\.sqlite|[^/]+\.sqlite\.(?:backup|memory-reindex|tmp)-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:-wal|-shm|-journal)?$/iu;function normalizePosix(e){if(!e)return e;return path.posix.normalize(e.replaceAll(`\\`,`/`))}function isUnder(e,t){if(!t)return false;const n=t.endsWith(`/`)?t:`${t}/`;return e===t||e.startsWith(n)}function hasExtension(e,t){const n=path.posix.extname(e).toLowerCase();return t.includes(n)}function isTransientBackupPath(e){return/.+\.(?:sock$|pid$|tmp(?:\.|$))/iu.test(path.posix.basename(normalizePosix(e)))}function isTransientSqliteBackupPath(e){const t=normalizePosix(e);return SQLITE_MEMORY_TRANSIENT_PATH_PATTERN.test(t)}function relativePathParts(e,t){return isUnder(e,t)?path.posix.relative(t,e).split(`/`).filter(Boolean):[]}function isVolatileBackupPath(e,t){if(!e)return false;const n=normalizePosix(e);for(const e of t.stateDirs){if(!e)continue;const t=normalizePosix(e);if(isUnder(n,t)&&isLegacyAuditMigrationBackupPath(n,t))return true;const r=relativePathParts(n,path.posix.join(t,`browser`));if(r.length===3&&r[1]===`user-data`&&CHROMIUM_SINGLETON_FILES.has(r[2]??``))return true;for(const[e,r]of VOLATILE_DIRECTORY_RULES)if((!r||hasExtension(n,r))&&e.some(e=>isUnder(n,path.posix.join(t,e))))return true;if(hasExtension(n,[`.jsonl`,`.log`])){const e=relativePathParts(n,path.posix.join(t,`agents`));if(e.length>=3&&e[1]===`sessions`)return true}if(isUnder(n,t)&&isTransientBackupPath(n))return true}return false}export{isLegacyAuditMigrationBackupPath as a,hasLegacyAuditBackupSources as i,isTransientSqliteBackupPath as n,isVolatileBackupPath as r,isTransientBackupPath as t};