UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.07 kB
import{a as e}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import"./openclaw-state-read-logger-Ix7jXPG1.mjs";import{v as t}from"./openclaw-state-read-read-open-flags-CtNL1rJs.mjs";import{i as n,r,t as i}from"./openclaw-state-read-workspace-state-identity-CGvxbhyj.mjs";import a from"node:fs";import o from"node:path";import{isDeepStrictEqual as s}from"node:util";function rootFact(e){return e&&{dev:e.dev,ino:e.ino,mode:e.mode,isDirectory:e.isDirectory()}}function ignoreMissing(e){if(!t(e,`ENOENT`)&&!t(e,`ENOTDIR`))throw e}function captureObservation(e,t){let n=r(e),i=[rootFact(a.lstatSync(e,{bigint:!0,throwIfNoEntry:!1})),rootFact(a.statSync(e,{bigint:!0,throwIfNoEntry:!1}))],o=[];if(t)try{o=a.readdirSync(e).toSorted()}catch(e){ignoreMissing(e)}return{workspaceDir:e,canonical:n,root:i,names:t?o:void 0}}async function captureWorkspaceFilesystemEvidence(t,r=!1){let i=o.resolve(e(t));return{workspaceDir:i,canonical:await n(i),root:[rootFact(await a.promises.lstat(i,{bigint:!0}).catch(ignoreMissing)),rootFact(await a.promises.stat(i,{bigint:!0}).catch(ignoreMissing))],names:r?(await a.promises.readdir(i).catch(ignoreMissing)??[]).toSorted():void 0}}function assertObservation(e,t){let n=e.workspaceDir;if(t.canonical!==e.canonical)throw new i({aliasPath:n,storedWorkspacePath:e.canonical,currentWorkspacePath:t.canonical});if(e.root.some((e,n)=>e!==void 0&&(e.dev!==t.root[n]?.dev||e.ino!==t.root[n]?.ino||e.mode!==t.root[n]?.mode))||e.root[1]===void 0&&t.root[1]&&!t.root[1].isDirectory||!s(t.names,e.names))throw Error(`Workspace filesystem changed while preparing state for ${n}; retry workspace setup.`);for(let n=0;n<e.root.length;n++)e.root[n]??=t.root[n]}function assertWorkspaceFilesystemEvidence(e){assertObservation(e,captureObservation(e.workspaceDir,e.names!==void 0))}async function validateWorkspaceFilesystemEvidence(e){assertObservation(e,await captureWorkspaceFilesystemEvidence(e.workspaceDir,e.names!==void 0))}export{captureWorkspaceFilesystemEvidence as n,validateWorkspaceFilesystemEvidence as r,assertWorkspaceFilesystemEvidence as t};