UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.23 kB
import{a as e}from"./git-operation.worker-fs-safe-2XqdJR5K.mjs";import{t}from"./git-operation.worker-path-guards-B73RPnzx.mjs";import{Cn as n}from"./git-operation.worker.js";import{n as r}from"./git-operation.worker-staged-inputs-DZiTgX91.mjs";import{d as i,g as a,p as o}from"./git-operation.worker-workspace-manifest-DsRMcvMP.mjs";import{n as s,o as c}from"./git-operation.worker-workspace-manifest-comparison-E7MDmqwp.mjs";import{directoryContainsOnlyWorkspaceEntries as l,localPath as u,localWorkspaceNode as d}from"./git-operation.worker-workspace-reconcile-fs-2rlVLgX2.mjs";import{lstatSync as f}from"node:fs";import p from"node:fs/promises";async function localWorkspaceDescendantPaths(e,t,n,r,a){let c=[],l=[...t],d=0,f=0;for(;l.length>0;){let t=l.pop(),m=[];for await(let n of await p.opendir(u(e,t)))if(m.push(n.name),f+=1,f>25e4)throw Error(`Gateway workspace manifest has too many entries`);for(let f of m.toSorted()){let m=`${t}/${f}`;if(d+=Buffer.byteLength(m),d>67108864)throw Error(`Gateway workspace manifest paths exceed their byte limit`);if(o(m)){s(r,m)&&c.push(m);continue}if(i(m,await n(m),a))continue;c.push(m);let h=await p.lstat(u(e,m));h.isDirectory()&&!h.isSymbolicLink()&&l.push(m)}}return c}async function preflightWorkspaceApplyImpl(i){let m=i.buildCacheInputs!==void 0,h=r(await e(i.root)),g=new Set(i.buildCacheInputs),isRetainedInput=async e=>g.has(e)||await h(e),_=new Map(i.baseNodes),v=new Map(i.currentNodes),y=new Set(i.changedPaths),b=new Set([...y].filter(e=>_.get(e)?.type===`directory`&&v.get(e)?.type!==`directory`)),x=[...b].filter(e=>!s(b,e)),S=[];for(let e of x){let t=await p.lstat(u(i.root,e)).catch(()=>void 0);t?.isDirectory()&&!t.isSymbolicLink()&&S.push(e)}let C=await localWorkspaceDescendantPaths(i.root,S,isRetainedInput,new Set(x.filter(e=>v.has(e))),m),w=[.../* @__PURE__ */ new Set([...y,...C])].toSorted(),T=/* @__PURE__ */ new Set,E=/* @__PURE__ */ new Set,D=/* @__PURE__ */ new Set,O=/* @__PURE__ */ new Map,localNode=e=>n(O,e,()=>d(i.root,e));for(let e of w){if(s(D,e))continue;if(v.get(e)===void 0)try{if(!f(u(i.root,e),{throwIfNoEntry:!1}))continue}catch(e){if(t(e,`ENOENT`)||t(e,`ENOTDIR`))continue;throw e}let n=!1,r=!1;for(let t of a(e)){let e=_.get(t),i=v.get(t);if(!e&&!i){let e=await localNode(t);if(e&&e.type!==`directory`){E.add(t),D.add(t),n=!0;break}continue}let a=await localNode(t);if(!c(a,e)&&!c(a,i)){E.add(t),D.add(t),n=!0;break}e&&e.type!==`directory`&&!c(e,i)&&c(a,e)&&(r=!0)}if(n)continue;let d;if(r?d=void 0:(d=await localNode(e),d?.type!==`directory`||o(e)||_.has(e)&&v.has(e)||v.get(e)?.type===`directory`||!await l(i.root,e,isRetainedInput,void 0,m)||(d=void 0)),c(d,_.get(e)))y.has(e)&&T.add(e);else if(!c(d,v.get(e))){E.add(e);let t=v.get(e);(t?.type===`directory`&&d!==void 0&&d.type!==`directory`||t!==void 0&&t.type!==`directory`&&d?.type===`directory`)&&D.add(e)}}let k=[...E];for(let e of k)for(let t of a(e)){let e=v.get(t);if(y.has(t)&&e&&e.type!==`directory`){E.add(t),D.add(t);break}}let A=[...E].filter(e=>!s(D,e)).toSorted(),j=[...D].filter(e=>!s(D,e)).toSorted(),M=new Set(A),N=new Set(j);for(let e of T)(M.has(e)||s(N,e))&&T.delete(e);return{applyPaths:T,conflictPaths:A,blockingConflictPaths:j}}export{preflightWorkspaceApplyImpl};