mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
10425abb87
* fix(coding-agent): dedupe symlinked resources Fixes #3767 * refactor(coding-agent): extract canonicalizePath util for symlink resolution
37 lines
925 B
TypeScript
37 lines
925 B
TypeScript
import { realpathSync } from "node:fs";
|
|
|
|
/**
|
|
* Resolve a path to its canonical (real) form, following symlinks.
|
|
* Falls back to the raw path if resolution fails (e.g. the target does
|
|
* not exist yet), so that callers never crash on missing filesystem
|
|
* entries.
|
|
*/
|
|
export function canonicalizePath(path: string): string {
|
|
try {
|
|
return realpathSync(path);
|
|
} catch {
|
|
return path;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true if the value is NOT a package source (npm:, git:, etc.)
|
|
* or a URL protocol. Bare names and relative paths without ./ prefix
|
|
* are considered local.
|
|
*/
|
|
export function isLocalPath(value: string): boolean {
|
|
const trimmed = value.trim();
|
|
// Known non-local prefixes
|
|
if (
|
|
trimmed.startsWith("npm:") ||
|
|
trimmed.startsWith("git:") ||
|
|
trimmed.startsWith("github:") ||
|
|
trimmed.startsWith("http:") ||
|
|
trimmed.startsWith("https:") ||
|
|
trimmed.startsWith("ssh:")
|
|
) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|