UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.41 kB
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{n as runtimeProcessEntrypoints}from"./runtime-process-entrypoints-Dnd1WskT.mjs";import{a as resolveRuntimeWorkerUrl,n as resolveRuntimeWorkerArgv}from"./runtime-worker-url-Dqf-I1cs.mjs";import{t as _usingCtx}from"./usingCtx-CUVyQ_FT.mjs";import{a as WorkerTaskError}from"./src-D4Y-r8_m.mjs";import{i as withChildProcessOperation}from"./spawn-diagnostics-C-LTFiNq.mjs";import{r as prepareSandboxStateOwnerPath}from"./state-owner-path-CGpPdjBt.mjs";import{t as WorkerTaskPool}from"./worker-task-pool-Bg54sSAN.mjs";import{u as prepareSessionSourceEffect}from"./session-source-authority-Cun3s-rH.mjs";import{t as runCommandBuffersWithTimeout}from"./exec-runner-BiCq-T1F.mjs";import{o as validateWorkspaceFilesystemEvidence}from"./workspace-state-guard-Bv-hX6Uv.mjs";import{t as WORKTREE_CHECKOUT_TIMEOUT_MS}from"./git-2P0YMMKQ.mjs";import{i as setWorktreePreparationTemplate}from"./preparation-timing-CC2_vlen.mjs";import{deserialize}from"node:v8"; //!src/agents/worktrees/filesystem-native.ts function workerUrl(){return resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.fsSafeCopy)}function assertActive(e){e.signal?.throwIfAborted();e.commitGuard()}function checkReply(e){if(e.type===`failed`)throw Object.assign(new Error(e.message),{code:e.code})}async function read(e,t){assertActive(t);const n=resolveGlobalSingleton(Symbol.for(`openclaw.worktreeFilesystemReads`),()=>({}),e=>{e.closing??=(e.pool?.close()??Promise.resolve()).finally(()=>{e.pool=void 0;e.closing=void 0});return e.closing});if(n.closing)throw new WorkerTaskError(`Native worktree reads are closing; retry the operation`,`unavailable`);const r=await(n.pool??=new WorkerTaskPool({workerUrl:workerUrl(),workerClass:`reader`,idleTimeoutMs:3e4})).run(e,{inputBytes:e.type===`probe`?Buffer.byteLength(e.parent):e.type===`acl`?Buffer.byteLength(e.path):e.paths.reduce((e,t)=>e+Buffer.byteLength(t),0),signal:t.signal,timeoutMs:WORKTREE_CHECKOUT_TIMEOUT_MS});assertActive(t);checkReply(r);return r}async function prepareWorktreeFilesystemMutation(e,t){for(const n of/* @__PURE__ */ new Set([...e.workerAuthority?.workspaceEvidence??[],...t.workspaceEvidence??[]]))await validateWorkspaceFilesystemEvidence(n);if(e.workerAuthority?.stateOwnerPath)await prepareSandboxStateOwnerPath(e.workerAuthority.stateOwnerPath);e.signal?.throwIfAborted();t.assertCurrent()}async function write(e,t){try{var n=_usingCtx();assertActive(t);const r=await prepareSessionSourceEffect(t.commitGuard);n.a({[Symbol.asyncDispose]:async()=>await r.release?.()});const i=await withChildProcessOperation(`worktree.filesystem`,()=>runCommandBuffersWithTimeout([process.execPath,...resolveRuntimeWorkerArgv(workerUrl())],{input:JSON.stringify(e),prepareInput:()=>prepareWorktreeFilesystemMutation(t,r),beforeInput:()=>{t.signal?.throwIfAborted();r.assertCurrent()},signal:t.signal,timeoutMs:WORKTREE_CHECKOUT_TIMEOUT_MS,killGraceMs:WORKTREE_CHECKOUT_TIMEOUT_MS,killProcessTree:true,requireProcessTreeExtinction:true,maxOutputBytes:65536}));t.signal?.throwIfAborted();r.assertCurrent();if(i.code!==0||i.termination!==`exit`)throw new Error(`Native worktree ${e.type} failed: ${i.termination}`);const a=deserialize(i.stdout);checkReply(a);if(a.type!==`written`)throw new Error(`Native worktree operation returned no completion receipt`)}catch(e){n.e=e}finally{await n.d()}}const nativeWorktreeFilesystem={async probe(e,t){const n=await read({type:`probe`,parent:e},t);if(n.type!==`probe`)throw new Error(`Native worktree check returned an invalid reply`);setWorktreePreparationTemplate(`unavailable`,{backend:n.backend??`none`,reason:n.backend?`filesystem-supported`:n.nativeMode===`off`?`native-disabled`:`filesystem-unsupported-or-native-unavailable`});return n.backend},async readAcl(e,t){const n=await read({type:`acl`,path:e},t);if(n.type!==`acl`)throw new Error(`Native worktree ACL inspection returned an invalid reply`);return n.acl},async readMetadata(e,t){const n=await read({type:`metadata`,paths:e},t);if(n.type!==`metadata`)throw new Error(`Native worktree metadata returned an invalid reply`);return n.entries},createSource(e,t){return write({type:`create`,destination:e},t)},remove(e,t){return write({type:`remove`,destination:e},t)},copy(e,t,n){return write({type:`copy`,source:e,destination:t},n)}};export{prepareWorktreeFilesystemMutation as n,nativeWorktreeFilesystem as t};