/** * Path resolution for tool arguments. * * Mirrors Pi's built-in tool convention: a leading "@" is stripped before * resolving, and relative paths resolve against the session working directory. */ import { isAbsolute, resolve } from "node:path"; import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; /** Strips a leading "@" prefix that some models add to file paths. */ export function stripLeadingAt(target: string): string { return target.startsWith("@") ? target.slice(1) : target; } /** Resolves a tool path argument against the session working directory. */ export function resolveTargetPath(ctx: Pick, target: string): string { const cleaned = stripLeadingAt(target.trim()); if (cleaned === "" || cleaned === ".") { return ctx.cwd; } return isAbsolute(cleaned) ? cleaned : resolve(ctx.cwd, cleaned); }