From ec092ca498a4576deedfde203145f06ddbc9206f Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 10 Mar 2025 21:25:04 -0700 Subject: [PATCH] use relative paths and fix URI resolution in codebase repo map retrieval --- core/context/retrieval/repoMapRequest.ts | 15 +++++++++------ core/util/pathToUri.ts | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/context/retrieval/repoMapRequest.ts b/core/context/retrieval/repoMapRequest.ts index 5a4f9be2a..ee0d5aaf7 100644 --- a/core/context/retrieval/repoMapRequest.ts +++ b/core/context/retrieval/repoMapRequest.ts @@ -1,8 +1,8 @@ import { Chunk, ContinueConfig, IDE, ILLM } from "../.."; import { getModelByRole } from "../../config/util"; import generateRepoMap from "../../util/generateRepoMap"; +import { resolveRelativePathInDir } from "../../util/ideUtils"; import { renderChatMessage } from "../../util/messageContent"; -import { localPathToUri } from "../../util/pathToUri"; const SUPPORTED_MODEL_TITLE_FAMILIES = [ "claude-3", @@ -49,14 +49,14 @@ export async function requestFilesFromRepoMap( const repoMap = await generateRepoMap(llm, ide, { dirUris: filterDirUri ? [filterDirUri] : undefined, includeSignatures: false, - outputRelativeUriPaths: false, + outputRelativeUriPaths: true, }); const prompt = `${repoMap} Given the above repo map, your task is to decide which files are most likely to be relevant in answering a question. Before giving your answer, you should write your reasoning about which files/folders are most important. This thinking should start with a tag, followed by a paragraph explaining your reasoning, and then a closing tag on the last line. -After this, your response should begin with a tag, followed by a list of each file, one per line, and then a closing tag on the last line. You should select between 5 and 10 files. The names that you list should be the full path from the root of the repo, not just the basename of the file. +After this, your response should begin with a tag, followed by a list of each file, one per line, and then a closing tag on the last line. You should select between 5 and 10 files. The names that you list should be the exact relative path that you saw in the repo map, not just the basename of the file. This is the question that you should select relevant files for: "${input}"`; @@ -78,11 +78,14 @@ This is the question that you should select relevant files for: "${input}"`; ?.split("")[0] ?.split("\n") .filter(Boolean) - .map((uri) => uri.trim()); + .map((filepath) => filepath.trim()); const chunks = await Promise.all( filepaths.map(async (filepath) => { - const uri = localPathToUri(filepath); + const uri = await resolveRelativePathInDir(filepath, ide); + if (!uri) { + return undefined; + } const content = await ide.readFile(filepath); const lineCount = content.split("\n").length; const chunk: Chunk = { @@ -97,7 +100,7 @@ This is the question that you should select relevant files for: "${input}"`; }), ); - return chunks; + return chunks.filter((c) => c !== undefined) as Chunk[]; } catch (e) { console.debug("Error requesting files from repo map", e); return []; diff --git a/core/util/pathToUri.ts b/core/util/pathToUri.ts index 36c2bc35f..ce83563fd 100644 --- a/core/util/pathToUri.ts +++ b/core/util/pathToUri.ts @@ -6,6 +6,7 @@ import * as URI from "uri-js"; // Converts a local path to a file:/// URI export function localPathToUri(path: string) { + // This may incidentally solve bugs, but it is primarily here to warn us if we accidentally try to double-convert. It doesn't handle other URI schemes. if (path.startsWith("file://")) { console.warn("localPathToUri: path already starts with file://"); return path;