Files
openclaw/src/agents/workspace-dir.ts
Peter Steinberger 683aa09b55 refactor(media): harden localRoots bypass (#16739)
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 89dce69f50
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
2026-02-15 03:27:01 +01:00

21 lines
663 B
TypeScript

import path from "node:path";
import { resolveUserPath } from "../utils.js";
export function normalizeWorkspaceDir(workspaceDir?: string): string | null {
const trimmed = workspaceDir?.trim();
if (!trimmed) {
return null;
}
const expanded = trimmed.startsWith("~") ? resolveUserPath(trimmed) : trimmed;
const resolved = path.resolve(expanded);
// Refuse filesystem roots as "workspace" (too broad; almost always a bug).
if (resolved === path.parse(resolved).root) {
return null;
}
return resolved;
}
export function resolveWorkspaceRoot(workspaceDir?: string): string {
return normalizeWorkspaceDir(workspaceDir) ?? process.cwd();
}