UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.44 kB
import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{n as OPENCLAW_STATE_SCHEMA_VERSION}from"./openclaw-schema-versions-rhFQpVhP.mjs";import"./openclaw-state-db-contract-G6fQNIi2.mjs";import{m as withExistingOpenClawStateDatabaseArtifactPreservingReadOnlyAsync}from"./openclaw-state-db-readonly-Cd5_cxBs.mjs";import{t as OpenClawStateLeaseAcquisitionError}from"./openclaw-state-lease-error-DCUL0v5x.mjs";import{o as readStateSchemaContentVersion}from"./openclaw-state-db-schema-version-DreEd78i.mjs";import{t as scrubDoctorErrorMessage}from"./doctor-error-message-Crthe8x4.mjs";import{r as listHealthChecks}from"./health-check-registry-qx2G8L6q.mjs";import{n as healthFindingMeetsSeverity,r as isHealthCheckEnabledByDefault,t as HEALTH_FINDING_SEVERITY_RANK}from"./health-checks-bdwCtNe-.mjs"; //!src/flows/doctor-lint-flow.ts const stateSchemaHealthCheck={id:`core/doctor/state-schema`,kind:`core`,description:`Shared state migrations require explicit repair.`,async detect(e){const[{readRetainedAgentDeletionsFromDatabase:t},{readAgentDatabasePreflightTargets:n}]=await Promise.all([import(`./agent-deletion-journal.read-jJSnCF6q.mjs`),import(`./openclaw-agent-db-registry.read-BR9-koS2.mjs`)]);const r=await withExistingOpenClawStateDatabaseArtifactPreservingReadOnlyAsync(({db:e,path:r})=>{const i=t(e,r);const a=i.status===`present`?i.held:i.status===`unavailable`?[...n(e,r),...i.known?.held??[]]:[];return{version:readStateSchemaContentVersion(e),path:r,journal:i,held:[...new Map(a.map(e=>[JSON.stringify([e.agentId,e.path]),e])).values()]}},{env:e.env});if(!r)return[];const i=formatCliCommand(`openclaw doctor --fix`,e.env);const a=r.journal.status===`unavailable`?r.journal:void 0;const o={checkId:`core/doctor/agent-deletion-journal`,severity:`warning`,errorCode:a?`agent-deletion-journal-${a.cause}`:`agent-deletion-journal-held`,fixHint:`Run ${i} to verify deletion history and ownership, and back up configured stores before restoration; follow its guidance for stores still held.`};const s=r.held.map(e=>({...o,target:e.agentId,path:e.path,message:`Held agent ${e.agentId} database ${e.path}: ${a?.reason??`deletion journal reconstructed`}. The store remains untouched until ownership can be verified.`}));if(a&&s.length===0)s.push({...o,path:r.path,message:a.reason});if(r.version>=40)return s;return[...s,{checkId:`core/doctor/state-schema`,severity:`warning`,path:r.path,requirement:`state-schema-migration-pending`,message:`Shared state schema migration pending (${r.version} → ${40}); run ${i}.`,fixHint:`Run \`${i}\` to migrate the shared state database.`}]}};async function runDoctorLintChecks(e,t={}){const n=t.checks??listHealthChecks();const r=t.skipIds instanceof Set?t.skipIds:new Set(t.skipIds??[]);const i=t.onlyIds instanceof Set?t.onlyIds:new Set(t.onlyIds??[]);const a=new Set(n.map(e=>e.id));const o=t.includeAllChecks===true;const s=n.filter(e=>{if(i.size>0&&!i.has(e.id))return false;if(i.size===0&&!o&&!isHealthCheckEnabledByDefault(e))return false;return!r.has(e.id)});const c=[];for(const e of i){let t;if(!a.has(e))t=`Unknown health check id selected by --only: ${e}.`;else if(s.length===0&&r.has(e))t=`Health check ${e} cannot be selected by --only and excluded by --skip.`;else continue;c.push({checkId:`core/doctor/lint-selection`,severity:`error`,message:t,path:e})}for(const t of s)try{const n=await t.detect(e);for(const e of n)c.push(e)}catch(e){const n=e instanceof OpenClawStateLeaseAcquisitionError&&e.outcome.kind===`aborted`?e.outcome:void 0;c.push({checkId:t.id,severity:n?`info`:`error`,...n?{errorCode:`OPENCLAW_STATE_LEASE_ABORTED`}:{},message:n?`state lease inspection not performed: aborted after ${n.elapsedMs} ms by the caller's signal`:`health check threw: ${scrubDoctorErrorMessage(e)}`})}c.sort(compareFindings);return{findings:c,checksRun:s.length,checksSkipped:n.length-s.length}}function selectUpdateReadinessChecks(e,t){return e.filter(e=>`updateReadiness`in e&&e.updateReadiness===t)}function compareFindings(e,t){const n=HEALTH_FINDING_SEVERITY_RANK[t.severity]-HEALTH_FINDING_SEVERITY_RANK[e.severity];if(n!==0)return n;const r=e.checkId.localeCompare(t.checkId);if(r!==0)return r;return(e.path??``).localeCompare(t.path??``)}function exitCodeFromFindings(e,t=`warning`){return e.some(e=>healthFindingMeetsSeverity(e,t))?1:0}export{stateSchemaHealthCheck as i,runDoctorLintChecks as n,selectUpdateReadinessChecks as r,exitCodeFromFindings as t};