@sema-agent/core
Version:
Stateless, task-oriented AI agent core
19 lines (18 loc) • 1.13 kB
JavaScript
import { anchorSpelling, win32NamespaceScreen } from "../tools/fs/safety.js";
import { isUncSpelling } from "./unc-spelling.js";
export async function symlinkChainHops(env, path, signal, family, baseCwd) {
if (typeof env.canonicalChain !== "function")
return { ok: false, cause: "the environment declares no symlink-chain reader", asked: false };
const screened = win32NamespaceScreen(path, family);
if (!screened.ok)
return { ok: false, cause: "a namespace spelling the chain reader does not walk", asked: false };
const spelled = screened.spelled;
if (family === "win" && isUncSpelling(spelled))
return { ok: false, cause: "a network share spelling the chain reader does not walk", asked: false };
const target = baseCwd !== undefined && baseCwd.length > 0 ? anchorSpelling(family, baseCwd, spelled) : spelled;
const chain = await env.canonicalChain(target, signal);
return chain.ok ? { ok: true, hops: chain.value.hops } : { ok: false, cause: chain.error.message, asked: true };
}
export function chainHopsOrNone(reading) {
return reading.ok ? reading.hops : [];
}