mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 06:59:48 +00:00
* refactor: extract filesystem safety primitives * refactor: use fs-safe for file access helpers * refactor: reuse fs-safe for media reads * refactor: use fs-safe for image reads * refactor: reuse fs-safe in qqbot media opener * refactor: reuse fs-safe for local media checks * refactor: consume cleaner fs-safe api * refactor: align fs-safe json option names * fix: preserve fs-safe migration contracts * refactor: use fs-safe primitive subpaths * refactor: use grouped fs-safe subpaths * refactor: align fs-safe api usage * refactor: adapt private state store api * chore: refresh proof gate * refactor: follow fs-safe json api split * refactor: follow reduced fs-safe surface * build: default fs-safe python helper off * fix: preserve fs-safe plugin sdk aliases * refactor: consolidate fs-safe usage * refactor: unify fs-safe store usage * refactor: trim fs-safe temp workspace usage * refactor: hide low-level fs-safe primitives * build: use published fs-safe package * fix: preserve outbound recovery durability after rebase * chore: refresh pr checks
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { isPathInside } from "../infra/path-guards.js";
|
|
import { normalizeAgentId } from "../routing/session-key.js";
|
|
import { lowercasePreservingWhitespace } from "../shared/string-coerce.js";
|
|
import { listAgentEntries, resolveAgentWorkspaceDir } from "./agent-scope.js";
|
|
|
|
function normalizeWorkspacePathForComparison(input: string): string {
|
|
const resolved = path.resolve(input.replaceAll("\0", ""));
|
|
let normalized = resolved;
|
|
try {
|
|
normalized = fs.realpathSync.native(resolved);
|
|
} catch {
|
|
// Keep lexical path for non-existent directories.
|
|
}
|
|
if (process.platform === "win32") {
|
|
return lowercasePreservingWhitespace(normalized);
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
function workspacePathsOverlap(left: string, right: string): boolean {
|
|
const normalizedLeft = normalizeWorkspacePathForComparison(left);
|
|
const normalizedRight = normalizeWorkspacePathForComparison(right);
|
|
return (
|
|
isPathInside(normalizedRight, normalizedLeft) || isPathInside(normalizedLeft, normalizedRight)
|
|
);
|
|
}
|
|
|
|
export function findOverlappingWorkspaceAgentIds(
|
|
cfg: OpenClawConfig,
|
|
agentId: string,
|
|
workspaceDir: string,
|
|
): string[] {
|
|
const entries = listAgentEntries(cfg);
|
|
const normalizedAgentId = normalizeAgentId(agentId);
|
|
const overlappingAgentIds: string[] = [];
|
|
for (const entry of entries) {
|
|
const otherAgentId = normalizeAgentId(entry.id);
|
|
if (otherAgentId === normalizedAgentId) {
|
|
continue;
|
|
}
|
|
const otherWorkspace = resolveAgentWorkspaceDir(cfg, otherAgentId);
|
|
if (workspacePathsOverlap(workspaceDir, otherWorkspace)) {
|
|
overlappingAgentIds.push(otherAgentId);
|
|
}
|
|
}
|
|
return overlappingAgentIds;
|
|
}
|