openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
108 lines (107 loc) • 3.85 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { n as runtimeProcessEntrypoints } from "./runtime-process-entrypoints-qiyJvDDT.mjs";
import { a as resolveRuntimeWorkerUrl, n as resolveRuntimeWorkerArgv } from "./runtime-worker-url-DRDkoS4J.mjs";
import { a as WorkerTaskError } from "./src-Dkfkl2Oz.mjs";
import { i as withChildProcessOperation } from "./spawn-diagnostics-DBVI9KzR.mjs";
import { t as WorkerTaskPool } from "./worker-task-pool-BshJjv1P.mjs";
import { t as runCommandBuffersWithTimeout } from "./exec-runner-Br73vG-X.mjs";
import { t as WORKTREE_CHECKOUT_TIMEOUT_MS } from "./git-BBx5S0aA.mjs";
import { n as setWorktreePreparationTemplate } from "./preparation-timing-YO2wGpby.mjs";
import { deserialize } from "node:v8";
//#region 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 write(e, t) {
assertActive(t);
const n = await withChildProcessOperation("worktree.filesystem", () => runCommandBuffersWithTimeout([process.execPath, ...resolveRuntimeWorkerArgv(workerUrl())], {
input: JSON.stringify(e),
beforeInput: () => assertActive(t),
signal: t.signal,
timeoutMs: WORKTREE_CHECKOUT_TIMEOUT_MS,
killGraceMs: WORKTREE_CHECKOUT_TIMEOUT_MS,
killProcessTree: true,
requireProcessTreeExtinction: true,
maxOutputBytes: 65536
}));
assertActive(t);
if (n.code !== 0 || n.termination !== "exit") throw new Error(`Native worktree ${e.type} failed: ${n.termination}`);
const r = deserialize(n.stdout);
checkReply(r);
if (r.type !== "written") throw new Error("Native worktree operation returned no completion receipt");
}
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);
},
copy(e, t, n) {
return write({
type: "copy",
source: e,
destination: t
}, n);
}
};
//#endregion
export { nativeWorktreeFilesystem as t };