/** * Path Normalization Utility * * Provides cross-platform path normalization with security features: * - Tilde (~) expansion * - Windows environment variable expansion * - WSL path conversion * - Canonical path resolution * - Path traversal validation */ /** * Normalize a path with cross-platform support * * @param input - Path to normalize (can contain ~, env vars, WSL paths) * @param options - Normalization options * @returns Absolute, canonical path * @throws Error if path traversal is detected outside allowed boundaries * * Features: * - Expands ~ to user home directory * - Expands Windows environment variables (%VAR%) * - Converts WSL paths (/mnt/c/...) to Windows paths (C:\...) * - Resolves relative paths (., ..) * - Resolves symlinks to canonical paths * - Validates against path traversal attacks * * @example * ```ts * const home = normalizePath('~/documents'); * // => '/home/user/documents' * * const abs = normalizePath('../parent'); * // => '/absolute/path/to/parent' * * const wsl = normalizePath('/mnt/c/Users/name'); * // => 'C:\\Users\\name' (on WSL) * ``` */ export declare function normalizePath(input: string, options?: { /** Base path for relative path resolution. Defaults to process.cwd() */ basePath?: string; /** Whether to validate against path traversal. Defaults to true */ validateTraversal?: boolean; /** Allowed root path for traversal validation. Defaults to repo root or workspace root */ allowedRoot?: string; /** Whether to resolve symlinks. Defaults to true */ resolveSymlinks?: boolean; }): string; /** * Find the repository root by walking up the directory tree * * @param startPath - Starting path for the search. Defaults to process.cwd() * @returns Repository root path, or null if not found * * Looks for .git directory as indicator of repository root. */ export declare function findRepoRoot(startPath?: string): string | null; /** * Find the repository root with error handling * * @param startPath - Starting path for the search. Defaults to process.cwd() * @returns Repository root path * @throws Error if repository root is not found * * @example * ```ts * try { * const root = getRepoRoot(); * console.log(`Repository root: ${root}`); * } catch (error) { * console.error('Not in a git repository'); * } * ``` */ export declare function getRepoRoot(startPath?: string): string; /** * Get workspace root from environment or detect from repository * * @returns Workspace root path * * Priority: * 1. LEX_WORKSPACE_ROOT environment variable * 2. Repository root (from .git detection) * 3. Current working directory */ export declare function getWorkspaceRoot(): string; /** * Expand a path that may contain tokens and normalize it * * This is a convenience function that combines token expansion * with path normalization. For full token expansion including * date/time tokens, use the expandTokens function from the tokens module. * * @param input - Path that may contain path-specific tokens like ~ * @param options - Normalization options * @returns Normalized absolute path */ export declare function expandPath(input: string, options?: Parameters[1]): string;