UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

39 lines (38 loc) 1.81 kB
import { r as lowercasePreservingWhitespace } from "./string-coerce-mnp54Vah.js"; import { i as isPathInside } from "./path-BlG8lhgR.js"; import "./path-guards-CBe_wA_B.js"; import "./agent-scope-MrLta7Pq.js"; import { u as normalizeAgentId } from "./session-key-B_NoIfpX.js"; import { o as resolveAgentWorkspaceDir, t as listAgentEntries } from "./agent-scope-config-CgCYpZfK.js"; import fs from "node:fs"; import path from "node:path"; //#region src/agents/agent-delete-safety.ts /** Safety checks for deleting agents whose workspaces may overlap other agents. */ function normalizeWorkspacePathForComparison(input) { const resolved = path.resolve(input.replaceAll("\0", "")); let normalized = resolved; try { normalized = fs.realpathSync.native(resolved); } catch {} if (process.platform === "win32") return lowercasePreservingWhitespace(normalized); return normalized; } function workspacePathsOverlap(left, right) { const normalizedLeft = normalizeWorkspacePathForComparison(left); const normalizedRight = normalizeWorkspacePathForComparison(right); return isPathInside(normalizedRight, normalizedLeft) || isPathInside(normalizedLeft, normalizedRight); } /** Lists other agents whose workspaces overlap a candidate delete target. */ function findOverlappingWorkspaceAgentIds(cfg, agentId, workspaceDir) { const entries = listAgentEntries(cfg); const normalizedAgentId = normalizeAgentId(agentId); const overlappingAgentIds = []; for (const entry of entries) { const otherAgentId = normalizeAgentId(entry.id); if (otherAgentId === normalizedAgentId) continue; if (workspacePathsOverlap(workspaceDir, resolveAgentWorkspaceDir(cfg, otherAgentId))) overlappingAgentIds.push(otherAgentId); } return overlappingAgentIds; } //#endregion export { findOverlappingWorkspaceAgentIds as t };