openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.19 kB
JavaScript
import{t as e}from"./git-operation.worker-path-guards-B3dt-SRh.mjs";import{m as t}from"./git-operation.worker-git-C2q2uQ5t.mjs";import{d as n,v as r}from"./git-operation.worker-schemas-OtWwONNf.mjs";import{c as i,d as a,u as o}from"./git-operation.worker-workspace-manifest-Zk1wvpHZ.mjs";import{a as s,n as c}from"./git-operation.worker-workspace-manifest-comparison-B0otBJpG.mjs";import{directoryContainsOnlyWorkspaceEntries as l,localPath as u,localWorkspaceNode as d}from"./git-operation.worker-workspace-reconcile-fs-BmK2VKZq.mjs";import f from"node:fs/promises";import{lstatSync as p}from"node:fs";async function localWorkspaceDescendantPaths(e,t,n,r,a){let s=[],l=[...t],d=0,p=0;for(;l.length>0;){let t=l.pop(),m=[];for await(let n of await f.opendir(u(e,t)))if(m.push(n.name),p+=1,p>25e4)throw Error(`Gateway workspace manifest has too many entries`);for(let p of m.toSorted()){let m=`${t}/${p}`;if(d+=Buffer.byteLength(m),d>67108864)throw Error(`Gateway workspace manifest paths exceed their byte limit`);if(o(m)){c(r,m)&&s.push(m);continue}if(i(m,await n(m),a))continue;s.push(m);let h=await f.lstat(u(e,m));h.isDirectory()&&!h.isSymbolicLink()&&l.push(m)}}return s}async function preflightWorkspaceApplyImpl(i){let m=i.buildCacheInputs!==void 0,h=n(await r(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=>!c(b,e)),S=[];for(let e of x){let t=await f.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=>t(O,e,()=>d(i.root,e));for(let t of w){if(c(D,t))continue;if(v.get(t)===void 0)try{if(!p(u(i.root,t),{throwIfNoEntry:!1}))continue}catch(t){if(e(t,`ENOENT`)||e(t,`ENOTDIR`))continue;throw t}let n=!1,r=!1;for(let e of a(t)){let t=_.get(e),i=v.get(e);if(!t&&!i){let t=await localNode(e);if(t&&t.type!==`directory`){E.add(e),D.add(e),n=!0;break}continue}let a=await localNode(e);if(!s(a,t)&&!s(a,i)){E.add(e),D.add(e),n=!0;break}t&&t.type!==`directory`&&!s(t,i)&&s(a,t)&&(r=!0)}if(n)continue;let d;if(r?d=void 0:(d=await localNode(t),d?.type===`directory`&&!o(t)&&(!_.has(t)||!v.has(t))&&v.get(t)?.type!==`directory`&&await l(i.root,t,isRetainedInput,void 0,m)&&(d=void 0)),s(d,_.get(t)))y.has(t)&&T.add(t);else if(!s(d,v.get(t))){E.add(t);let e=v.get(t);(e?.type===`directory`&&d!==void 0&&d.type!==`directory`||e!==void 0&&e.type!==`directory`&&d?.type===`directory`)&&D.add(t)}}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=>!c(D,e)).toSorted(),j=[...D].filter(e=>!c(D,e)).toSorted(),M=new Set(A),N=new Set(j);for(let e of T)(M.has(e)||c(N,e))&&T.delete(e);return{applyPaths:T,conflictPaths:A,blockingConflictPaths:j}}export{preflightWorkspaceApplyImpl};