diff --git a/core/tools/implementations/lsTool.ts b/core/tools/implementations/lsTool.ts index c8c7530609..ca8badebe1 100644 --- a/core/tools/implementations/lsTool.ts +++ b/core/tools/implementations/lsTool.ts @@ -2,25 +2,20 @@ import ignore from "ignore"; import { ToolImpl } from "."; import { walkDir } from "../../indexing/walkDir"; -import { resolveInputPath } from "../../util/pathResolver"; import { ContinueError, ContinueErrorReason } from "../../util/errors"; - -export function resolveLsToolDirPath(dirPath: string | undefined) { - if (!dirPath || dirPath === ".") { - return "/"; - } - // Don't strip leading slash from absolute paths - let the resolver handle it - if (dirPath.startsWith(".") && !dirPath.startsWith("./")) { - return dirPath.slice(1); - } - return dirPath.replace(/\\/g, "/"); -} +import { resolveInputPath } from "../../util/pathResolver"; const MAX_LS_TOOL_LINES = 200; export const lsToolImpl: ToolImpl = async (args, extras) => { - const dirPath = resolveLsToolDirPath(args?.dirPath); - const resolvedPath = await resolveInputPath(extras.ide, dirPath); + if (!args.dirPath) { + throw new ContinueError( + ContinueErrorReason.Unspecified, + `No paths to explore were provided`, + ); + } + + const resolvedPath = await resolveInputPath(extras.ide, args?.dirPath); if (!resolvedPath) { throw new ContinueError( ContinueErrorReason.DirectoryNotFound, diff --git a/core/tools/implementations/lsTool.vitest.ts b/core/tools/implementations/lsTool.vitest.ts index c3c571294d..095d6087c6 100644 --- a/core/tools/implementations/lsTool.vitest.ts +++ b/core/tools/implementations/lsTool.vitest.ts @@ -1,7 +1,7 @@ import { expect, test, vi } from "vitest"; import { ToolExtras } from "../.."; import * as walkDirModule from "../../indexing/walkDir"; -import { lsToolImpl, resolveLsToolDirPath } from "./lsTool"; +import { lsToolImpl } from "./lsTool"; vi.mock("../../indexing/walkDir"); @@ -12,30 +12,6 @@ const mockExtras = { }, } as unknown as ToolExtras; -test("resolveLsToolDirPath handles undefined path", () => { - expect(resolveLsToolDirPath(undefined)).toBe("/"); -}); - -test("resolveLsToolDirPath handles empty string", () => { - expect(resolveLsToolDirPath("")).toBe("/"); -}); - -test("resolveLsToolDirPath handles dot", () => { - expect(resolveLsToolDirPath(".")).toBe("/"); -}); - -test("resolveLsToolDirPath handles dot relative", () => { - expect(resolveLsToolDirPath("./hi")).toBe("./hi"); -}); - -test("resolveLsToolDirPath normalizes backslashes to forward slashes", () => { - expect(resolveLsToolDirPath("path\\to\\dir")).toBe("path/to/dir"); -}); - -test("resolveLsToolDirPath preserves forward slashes", () => { - expect(resolveLsToolDirPath("path/to/dir")).toBe("path/to/dir"); -}); - test("lsToolImpl truncates output when entries exceed MAX_LS_TOOL_LINES", async () => { // Generate more than MAX_LS_TOOL_LINES entries (which is 200) const mockEntries = Array.from({ length: 250 }, (_, i) => `file${i}.txt`); diff --git a/core/util/pathResolver.ts b/core/util/pathResolver.ts index 25fe758168..86c9a3d920 100644 --- a/core/util/pathResolver.ts +++ b/core/util/pathResolver.ts @@ -18,11 +18,11 @@ export interface ResolvedPath { */ async function isUriWithinWorkspace(ide: IDE, uri: string): Promise { const workspaceDirs = await ide.getWorkspaceDirs(); - const { foundInDir } = findUriInDirs(uri, workspaceDirs); + const { foundInDir, uri: foundUri } = findUriInDirs(uri, workspaceDirs); - // Check both: within workspace path AND file exists + // Check both: within workspace path AND resolved file exists if (foundInDir !== null) { - return await ide.fileExists(uri); + return await ide.fileExists(foundUri); } return false;