UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.3 kB
import{t as e}from"./fs-safe-copy.worker-errno-CsW5NI8i.mjs";import{r as t}from"./fs-safe-copy.worker-fs-safe-env-DlxNGTI7.mjs";import{n}from"./fs-safe-copy.worker-worker-native-error-CjDMMt9F.mjs";import{chmodSync as r,lstatSync as i,readdirSync as a,rmSync as o}from"node:fs";import s from"node:fs/promises";import c from"node:path";import{text as l}from"node:stream/consumers";import{setImmediate as u}from"node:timers/promises";import{serialize as d}from"node:v8";import{parentPort as f}from"node:worker_threads";import{configureFsSafeNative as p,getFsSafeNativeConfig as m}from"@openclaw/fs-safe/config";import{copyTree as h,createCloneSource as g,probeTreeClone as _,readCloneFileMetadata as v}from"@openclaw/fs-safe/copy";import{FsSafeError as y}from"@openclaw/fs-safe/errors";import{inspectDarwinAcl as b}from"@openclaw/fs-safe/permissions";import{fileStore as x}from"@openclaw/fs-safe/store";async function cloneRefsDirectory(e,t,n,r){let i=await s.lstat(e);if(!i.isDirectory())throw Error(`Worktree template is not a directory: ${e}`);let a=await s.readdir(e,{withFileTypes:!0});n.assertCurrent(),await s.mkdir(t,{mode:448});let o=await r(t);for(let i of a){let a=c.join(e,i.name),s=c.join(t,i.name);i.isDirectory()?await cloneRefsDirectory(a,s,n,r):(n.assertCurrent(),await o.copyIn(i.name,a,{clone:`always`,overwrite:!1,mkdir:!1,durable:!1,maxBytes:1/0,preserveSourceMode:!0,preserveMetadata:!0,sourceSymlinks:`copy-link`,sourceHardlinks:`allow`,mutationSymlinks:`reject`,signal:n.signal,assertBeforeMutation:n.assertCurrent}),n.assertCurrent(),await u())}n.assertCurrent(),await s.chmod(t,i.mode&511)}function failure(e){return{type:`failed`,message:e instanceof Error?e.message:String(e),...e instanceof y?{fsSafeCode:e.code}:{},...e instanceof Error&&e.cause!==void 0?{cause:n(e.cause)}:{},...e instanceof Error&&`code`in e&&typeof e.code==`string`?{code:e.code}:{}}}function prepareOwnedDirectoryRemoval(e){let t=i(e);if(t.isDirectory()){(t.mode&448)!=448&&r(e,t.mode&4095|448);for(let t of a(e,{withFileTypes:!0}))t.isDirectory()&&prepareOwnedDirectoryRemoval(c.join(e,t.name))}}if(t(),f){let e=m(),{assertSandboxStateOwnerPathCurrent:t}=await import(`./fs-safe-copy.worker-state-owner-path-CvjDCur7.mjs`),{assertWorkspaceFilesystemEvidence:r}=await import(`./fs-safe-copy.worker-workspace-state-guard-CduSW3Yf.mjs`),{withWorkerFsSafeNativeMode:i}=await import(`./fs-safe-copy.worker-worker-fs-safe-VO7MvVKF.mjs`),{workerMutationAssertion:a}=await import(`./fs-safe-copy.worker-worker-mutation-authority-Ck4Uf0nl.mjs`),{serveWorkerTasks:o}=await import(`./fs-safe-copy.worker-worker-task-server-DWnWmS5L.mjs`);p(e),o(async(e,o,s)=>{let c;try{switch(e.type){case`scratch`:{if(!o)throw Error(`Scratch cleanup requires its live host channel`);let{walkScratchTree:t}=await import(`./fs-safe-copy.worker-scratch-cleanup-tree-C8AOV2Fv.mjs`),n,r=a(e.decision,()=>o.notify(n),s.throwIfCancelled);return await s.runNativeSection(()=>t(e,s.throwIfCancelled,async e=>{n=e,r()}))}case`prune-store`:case`remove-store-file`:return await s.runNativeSection(()=>i(e.nativeMode,async()=>{let t=x({rootDir:e.rootDir,dirMode:448,mode:384});return e.type===`prune-store`?await t.pruneExpired(e.options):await t.remove(e.relativePath),{type:`written`}}));case`workspace-read`:return await s.runNativeSection(async()=>{let{executeWorkspaceFilesystemRead:t}=await import(`./fs-safe-copy.worker-workspace-filesystem.worker-Bvy7FwA5.mjs`);return i(e.nativeMode,()=>t(e))});case`workspace`:{if(!o)throw Error(`Workspace filesystem requires its live host channel`);let t=a(e.decision,()=>o.notify(`authority`),s.throwIfCancelled);return await s.runNativeSection(async()=>{let{executeWorkspaceFilesystemOperation:n}=await import(`./fs-safe-copy.worker-workspace-filesystem.worker-Bvy7FwA5.mjs`);return i(e.nativeMode,()=>n(e,t))})}case`refs-copy`:case`provision`:{c={copier:`portable`,batchCount:0,sourceBytes:0,spawnCount:0,spawnMs:0,childMs:0,authorityChecks:0,authorityMs:0};let n=c;if(!o)throw Error(`Worktree provisioning requires its live host channel`);let l=a(e.decision,()=>o.notify(`authority`),s.throwIfCancelled);return await s.runNativeSection(async()=>{let assertCurrent=()=>{let i=performance.now();n.authorityChecks++;try{for(let t of e.workspaceEvidence??[])r(t);e.stateOwnerPath&&t(e.stateOwnerPath),l()}finally{n.authorityMs+=performance.now()-i}};if(e.type===`refs-copy`)return await i(e.nativeMode,async()=>{let{root:t}=await import(`@openclaw/fs-safe/root`);await cloneRefsDirectory(e.source,e.destination,{signal:s.signal,assertCurrent},t)}),{type:`written`,workspaceEvidence:e.workspaceEvidence};let{copyProvisionedPaths:a}=await import(`./fs-safe-copy.worker-provisioned-copy-B2l228_I.mjs`);return{type:`provisioned`,paths:await a(e.source,e.destination,e.paths,{copyDetails:n,signal:s.signal,assertCurrent}),copyDetails:n,workspaceEvidence:e.workspaceEvidence}})}case`probe`:return{type:`probe`,backend:_(e.parent),nativeMode:m().mode};case`acl`:return{type:`acl`,acl:b(e.path)};case`metadata`:return{type:`metadata`,entries:await v(e.paths)};default:throw Error(`Unknown native worktree read operation`)}}catch(t){return e.type===`workspace-read`?{type:`workspace-read`,result:{ok:!1,reason:t instanceof RangeError?`validation`:`io`,error:n(t),...t instanceof y?{fsCode:t.code,details:t.details}:{}}}:e.type===`workspace`?{type:`workspace-failed`,error:n(t)}:{...failure(t),...c?{copyDetails:c}:{}}}})}else{let t=new AbortController,abort=()=>t.abort();process.on(`SIGTERM`,abort);let n={type:`written`};try{let r=JSON.parse(await l(process.stdin));switch(r.type){case`reclaim-plugin-captures`:{let{reclaimPluginCaptureBatch:e}=await import(`./fs-safe-copy.worker-plugin-source-capture-native-loads-CrDK1HL9.mjs`);n={type:`captures-reclaimed`,...await e(r.candidates)};break}case`remove`:try{o(r.destination,{recursive:!0,force:!0})}catch(t){if(!e(t,`EACCES`)&&!e(t,`EPERM`)&&!e(t,`ENOTEMPTY`))throw t;prepareOwnedDirectoryRemoval(r.destination),o(r.destination,{recursive:!0,force:!0})}break;case`create`:await g(r.destination,{signal:t.signal});break;case`copy`:await h(r.source,r.destination,{clone:`always`,signal:t.signal});break;default:throw Error(`Unknown native worktree operation`)}}catch(e){n=failure(e)}finally{process.off(`SIGTERM`,abort)}process.stdout.write(d(n))}export{};