/** * @file resolvePath.ts — resolves a path a chat reply names against the pane's * folder: an absolute one (POSIX, `~`-less, or `C:\…`) is kept, a relative one * (`server/lib/x.js`, `./a`, `../b`) is joined to `cwd` with `.`/`..` folded, * so the preview and the Changes panel see the same absolute path the agent meant. * @author Nguyễn Ngọc Trí Vĩ */ /** `path` as an absolute path; relative ones resolve against `cwd`. */ export function resolveIn(cwd: string, path: string): string { if (/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(path) || !cwd) return path; const parts = cwd.replace(/[\\/]+$/, "").split(/[\\/]/); for (const seg of path.split(/[\\/]/)) { if (seg === "" || seg === ".") continue; if (seg === "..") { if (parts.length > 1) parts.pop(); } else parts.push(seg); } return parts.join("/") || "/"; }