Merge branch 'continuedev:main' into patch-2

This commit is contained in:
Jacob 2025-06-21 23:04:52 +08:00 • committed by GitHub
commit fa7bc17f36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 56 additions and 19 deletions

2
core/index.d.ts vendored
View file

@ -783,7 +783,7 @@ export interface IDE {
getSearchResults(query: string, maxResults?: number): Promise<string>;
getFileResults(pattern: string): Promise<string[]>;
getFileResults(pattern: string, maxResults?: number): Promise<string[]>;
subprocess(command: string, cwd?: string): Promise<[string, string]>;

View file

@ -30,7 +30,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
openUrl: [string, void];
runCommand: [{ command: string; options?: TerminalOptions }, void];
getSearchResults: [{ query: string; maxResults?: number }, string];
getFileResults: [{ pattern: string }, string[]];
getFileResults: [{ pattern: string; maxResults?: number }, string[]];
subprocess: [{ command: string; cwd?: string }, [string, string]];
saveFile: [{ filepath: string }, void];
fileExists: [{ filepath: string }, boolean];

View file

@ -163,7 +163,7 @@ export class ReverseMessageIde {
});
this.on("getFileResults", (data) => {
return this.ide.getFileResults(data.pattern);
return this.ide.getFileResults(data.pattern, data.maxResults);
});
this.on("getProblems", (data) => {

View file

@ -12,7 +12,8 @@ export const globSearchTool: Tool = {
group: BUILT_IN_GROUP_NAME,
function: {
name: BuiltInToolNames.FileGlobSearch,
description: "Search for files in the project",
description:
"Search for files in the project. Output may be truncated; use targeted patterns",
parameters: {
type: "object",
required: ["pattern"],

View file

@ -1,12 +1,28 @@
import { ToolImpl } from ".";
import { ContextItem } from "../..";
const MAX_AGENT_GLOB_RESULTS = 100;
export const fileGlobSearchImpl: ToolImpl = async (args, extras) => {
const results = await extras.ide.getFileResults(args.pattern);
return [
const results = await extras.ide.getFileResults(
args.pattern,
MAX_AGENT_GLOB_RESULTS,
);
const contextItems: ContextItem[] = [
{
name: "File results",
description: "Results from file glob search",
content: results.join("\n"),
},
];
// In case of truncation, add a warning
if (results.length === MAX_AGENT_GLOB_RESULTS) {
contextItems.push({
name: "Truncation warning",
description: "Inform the model that results were truncated",
content: `Warning: the results above were truncated to the first ${MAX_AGENT_GLOB_RESULTS} files. If the results are not satisfactory, refine your search pattern`,
});
}
return contextItems;
};

View file

@ -238,7 +238,10 @@ class FileSystemIde implements IDE {
return "";
}
async getFileResults(pattern: string): Promise<string[]> {
async getFileResults(
pattern: string,
maxResults?: number,
): Promise<string[]> {
return [];
}

View file

@ -31,7 +31,8 @@ Continue includes several built-in tools which provide the model access to IDE f
- **Read file** (`builtin_read_file`): read the contents of a file within the project
- **Read currently open file** (`builtin_read_currently_open_file`): read the contents of the currently open file
- **Create new file** (`builtin_create_new_file`): Create a new file within the project, with path and contents specified by the model
- **Grep search** (`builtin_grep_search`): perform a `ripgrep` search within the project. Results are limited to 100 results and 5000 characters (model is warned if this is exceeded)
- **Exact search** (`builtin_exact_search`): perform a `ripgrep` search within the project
- **Glob search** (`builtin_file_glob_search`): perform a glob search on files in the project. Currently limits to 100 output and warns the Agent if limit reached.
- **Run terminal command** (`builtin_run_terminal_command`): run a terminal command from the workspace root
- **Search web** (`builtin_search_web`): Perform a web search to get top results
- **View diff** (`builtin_view_diff`): View the current working git diff

View file

@ -365,7 +365,7 @@ class IdeProtocolClient(
dataElement.toString(),
GetFileResultsParams::class.java
)
val results = ide.getFileResults(params.pattern)
val results = ide.getFileResults(params.pattern, params.maxResults)
respond(results)
}

View file

@ -315,11 +315,11 @@ class IntelliJIDE(
return getOpenFiles()
}
override suspend fun getFileResults(pattern: String): List<String> {
override suspend fun getFileResults(pattern: String, maxResults: Int?): List<String> {
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
try {
val command = GeneralCommandLine(
var commandArgs = mutableListOf<String>(
ripgrep,
"--files",
"--iglob",
@ -327,8 +327,14 @@ class IntelliJIDE(
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
".gitignore"
)
if (maxResults != null) {
commandArgs.add("--max-count")
commandArgs.add(maxResults.toString())
}
val command = GeneralCommandLine(commandArgs)
command.setWorkDirectory(project.basePath)
val results = ExecUtil.execAndGetOutput(command).stdout

View file

@ -23,7 +23,7 @@ typealias getTagsParams = String
data class GetSearchResultsParams(val query: String, val maxResults: Int?)
data class GetFileResultsParams(val pattern: String)
data class GetFileResultsParams(val pattern: String, val maxResults: Int?)
data class SaveFileParams(val filepath: String)

View file

@ -159,7 +159,7 @@ interface IDE {
suspend fun getSearchResults(query: String, maxResults: Int?): String
suspend fun getFileResults(pattern: String): List<String>
suspend fun getFileResults(pattern: String, maxResults: Int?): List<String>
// Note: This should be a `Pair<String, String>` but we use `List<Any>` because the keys of `Pair`
// will serialize to `first and `second` rather than `0` and `1` like in JavaScript

View file

@ -433,8 +433,10 @@ class VsCodeIde implements IDE {
});
}
async getFileResults(pattern: string): Promise<string[]> {
const MAX_FILE_RESULTS = 200;
async getFileResults(
pattern: string,
maxResults?: number,
): Promise<string[]> {
if (vscode.env.remoteName) {
// TODO better tests for this remote search implementation
// throw new Error("Ripgrep not supported, this workspace is remote");
@ -501,7 +503,7 @@ class VsCodeIde implements IDE {
const results = await vscode.workspace.findFiles(
pattern,
ignoreGlobs.size ? `{${ignoreGlobsArray.join(",")}}` : null,
MAX_FILE_RESULTS,
maxResults,
);
return results.map((result) => vscode.workspace.asRelativePath(result));
} else {
@ -515,12 +517,20 @@ class VsCodeIde implements IDE {
".continueignore",
"--ignore-file",
".gitignore",
...(maxResults ? ["--max-count", String(maxResults)] : []),
]);
results.push(dirResults);
}
return results.join("\n").split("\n").slice(0, MAX_FILE_RESULTS);
const allResults = results.join("\n").split("\n");
if (maxResults) {
// In the case of multiple workspaces, maxResults will be applied to each workspace
// And then the combined results will also be truncated
return allResults.slice(0, maxResults);
} else {
return allResults;
}
}
}

View file

@ -324,7 +324,7 @@ export class VsCodeMessenger {
return ide.getSearchResults(msg.data.query, msg.data.maxResults);
});
this.onWebviewOrCore("getFileResults", async (msg) => {
return ide.getFileResults(msg.data.pattern);
return ide.getFileResults(msg.data.pattern, msg.data.maxResults);
});
this.onWebviewOrCore("subprocess", async (msg) => {
return ide.subprocess(msg.data.command, msg.data.cwd);