From 19f081524b5383624e13f89fc659afb58014bd33 Mon Sep 17 00:00:00 2001 From: Andrea Pizzato Date: Wed, 3 Dec 2025 10:35:09 +0100 Subject: [PATCH 1/4] fix(lsTool): Remove custom path reinterpreter in favor of the IDE path resolver --- core/tools/implementations/lsTool.ts | 23 +++++++----------- core/tools/implementations/lsTool.vitest.ts | 26 +-------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/core/tools/implementations/lsTool.ts b/core/tools/implementations/lsTool.ts index c8c75306092..ca8badebe14 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 c3c571294d8..095d6087c6d 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`); From de930a748d0e70f5447c1fc62ca4d56e0e3d369c Mon Sep 17 00:00:00 2001 From: Andrea Pizzato Date: Wed, 3 Dec 2025 10:36:35 +0100 Subject: [PATCH 2/4] fix(pathResolver): Check the final computed URI for existence instead of the unresolved one --- core/util/pathResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/util/pathResolver.ts b/core/util/pathResolver.ts index 25fe7581688..1d06c87e424 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 if (foundInDir !== null) { - return await ide.fileExists(uri); + return await ide.fileExists(foundUri); } return false; From 931d455214f1adc9767e3b86b23d68daca64d842 Mon Sep 17 00:00:00 2001 From: Andrea Pizzato Date: Wed, 3 Dec 2025 11:59:47 +0100 Subject: [PATCH 3/4] chore(pathResolver): Enhance comments --- core/util/pathResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/util/pathResolver.ts b/core/util/pathResolver.ts index 1d06c87e424..aeafa48c476 100644 --- a/core/util/pathResolver.ts +++ b/core/util/pathResolver.ts @@ -20,7 +20,7 @@ async function isUriWithinWorkspace(ide: IDE, uri: string): Promise { const workspaceDirs = await ide.getWorkspaceDirs(); const { foundInDir, uri: foundUri } = findUriInDirs(uri, workspaceDirs); - // Check both: within workspace path AND file exists + // Check both: within workspace path AND the resolved file exists if (foundInDir !== null) { return await ide.fileExists(foundUri); } From 9a7d15b0a293eed8af5f88f7265d61e8d17531fb Mon Sep 17 00:00:00 2001 From: Andrea Pizzato Date: Wed, 3 Dec 2025 12:27:56 +0100 Subject: [PATCH 4/4] chore(pathResolver): Enhance comments --- core/util/pathResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/util/pathResolver.ts b/core/util/pathResolver.ts index aeafa48c476..86c9a3d920c 100644 --- a/core/util/pathResolver.ts +++ b/core/util/pathResolver.ts @@ -20,7 +20,7 @@ async function isUriWithinWorkspace(ide: IDE, uri: string): Promise { const workspaceDirs = await ide.getWorkspaceDirs(); const { foundInDir, uri: foundUri } = findUriInDirs(uri, workspaceDirs); - // Check both: within workspace path AND the resolved file exists + // Check both: within workspace path AND resolved file exists if (foundInDir !== null) { return await ide.fileExists(foundUri); }