Documentation
¶
Overview ¶
Package resolvepath resolves user-supplied resource paths the way Pi's resolvePath does. It sits below internal/codingagent and coding/packagecontent so both share one implementation. Ports packages/coding-agent/src/utils/paths.ts:75-106.
Index ¶
- func ComparisonKey(path string) string
- func FoldsCase() bool
- func HasComparisonKey(resolved, key string) bool
- func IsAbsolutePackagePath(input string) bool
- func IsPathWithin(parent, child string) bool
- func Normalize(path string) (string, error)
- func NormalizeUnicodeSpaces(s string) string
- func NormalizeWindowsShellPath(filePath string) string
- func OverridePlatform(goos string) (restore func())
- func PathsEqual(left, right string) bool
- func Resolve(input, baseDir string) (string, error)
- func ResolvePackagePath(input, baseDir string) (string, error)
- func ResolveTrimmed(input, baseDir string) (string, error)
- func ShortenHomePath(path, home string) string
- func Trim(input string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComparisonKey ¶
ComparisonKey is Pi's getPathComparisonKey: the resolved absolute path, case-folded on Windows because Windows paths are case-insensitive (`c:\Users` and `C:\Users` are the same directory). It does not touch the filesystem; call CanonicalizePath first when symlinks must compare equal. Use it only for comparison, never for display or filesystem access. A relative path that cannot be resolved because the working directory is gone keeps its spelling, where Pi's path.resolve throws.
func FoldsCase ¶
func FoldsCase() bool
FoldsCase reports whether paths compare case-insensitively on the current platform (Windows). Callers on a hot path use it to skip a comparison that ComparisonKey would only repeat.
func HasComparisonKey ¶
HasComparisonKey reports ComparisonKey(resolved) == key without allocating, for a resolved path already absolute and normalized as path.resolve leaves it, but for its separators (a path from filepath.Dir of one) and a key from ComparisonKey. On Windows it folds each rune as ComparisonKey's strings.ToLower does and compares in place; a walk that checks every ancestor of the working directory against one key uses it, where PathsEqual would resolve, lower-case and allocate both paths at every level.
func IsAbsolutePackagePath ¶
IsAbsolutePackagePath reports whether a Package path names its location without a base directory: after the package manager's trim and tilde and file:// URL expansion it is absolute, so it resolves to the same place from any settings directory. A path that does not expand is not absolute.
func IsPathWithin ¶
IsPathWithin is Pi's isPathWithin: child is parent or inside it, matching whole path segments (see ComparisonKey).
func Normalize ¶
Normalize applies Pi's default path normalization: a leading "~" or "~/" expands to the home directory and a file:// URL becomes its path through Node's fileURLToPath, whose errors it returns. An empty path stays empty.
func NormalizeUnicodeSpaces ¶
NormalizeUnicodeSpaces replaces each non-standard Unicode space with an ASCII space, Pi's resolvePath option normalizeUnicodeSpaces. It scans the path instead of running a regexp: a regexp match takes its matcher from a sync.Pool, whose per-P array the first use after a collection reallocates (GOMAXPROCS*128 bytes), and every read and write tool call resolves a path. Bytes that are not part of such a space, ill-formed UTF-8 included, are copied as they are, as ReplaceAllString copies them.
func NormalizeWindowsShellPath ¶
NormalizeWindowsShellPath converts a Git Bash, MSYS, Cygwin or WSL drive path to the form native Windows APIs accept.
upstream: utils/paths.ts normalizeWindowsShellPath
func OverridePlatform ¶
func OverridePlatform(goos string) (restore func())
OverridePlatform makes ComparisonKey, PathsEqual and IsPathWithin behave as on goos ("windows", or any other name for POSIX rules) until the returned function runs. It is for tests: production code never calls it.
func PathsEqual ¶
PathsEqual is Pi's pathsEqual: both paths name the same location (see ComparisonKey).
func Resolve ¶
Resolve normalizes input and baseDir, then resolves the input to an absolute path. An empty baseDir uses the process working directory.
func ResolvePackagePath ¶
ResolvePackagePath uses the package manager's HOME || homedir() tilde expansion and trims the input, without changing normalization of baseDir. Ports packages/coding-agent/src/core/package-manager.ts (resolvePath, resolvePathFromBase). Ports packages/coding-agent/src/core/package-manager.ts:221-223,2145-2151.
func ResolveTrimmed ¶
ResolveTrimmed is Resolve after String.prototype.trim, the { trim: true } option Pi's resource loader and package manager pass.
func ShortenHomePath ¶
ShortenHomePath replaces a leading home directory with "~" for display. A path outside home, a relative path and an empty home come back unchanged. Only whole path segments match: "/home/me2/x" is not under "/home/me". On Windows the match ignores case and the rest is written with backslashes. Ports packages/coding-agent/src/utils/paths.ts shortenHomePath (Pi 1be312b4, #10488).
Types ¶
This section is empty.