UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

24 lines (23 loc) • 1.45 kB
import { anchorSpelling, win32NamespaceScreen } from "../tools/fs/safety.js"; import { envErrorDetail } from "../tools/fs/env-error-detail.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: envErrorDetail(chain.error.message), asked: true }; } export function leafChainMayHold(walked, landedElsewhere, family) { const climbs = family === "win" ? /(^|[\\/])\.\.([\\/]|$)/ : /(^|\/)\.\.(\/|$)/; return landedElsewhere || walked.some((s) => s !== undefined && climbs.test(s)); } export function chainHopsOrNone(reading) { return reading.ok ? reading.hops : []; }