Skip to content

Commit fa7bc17

Browse files
authored
Merge branch 'continuedev:main' into patch-2
2 parents dbabee5 + e6406de commit fa7bc17

File tree

13 files changed

+56
-19
lines changed

13 files changed

+56
-19
lines changed

core/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ export interface IDE {
783783

784784
getSearchResults(query: string, maxResults?: number): Promise<string>;
785785

786-
getFileResults(pattern: string): Promise<string[]>;
786+
getFileResults(pattern: string, maxResults?: number): Promise<string[]>;
787787

788788
subprocess(command: string, cwd?: string): Promise<[string, string]>;
789789

core/protocol/ide.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
3030
openUrl: [string, void];
3131
runCommand: [{ command: string; options?: TerminalOptions }, void];
3232
getSearchResults: [{ query: string; maxResults?: number }, string];
33-
getFileResults: [{ pattern: string }, string[]];
33+
getFileResults: [{ pattern: string; maxResults?: number }, string[]];
3434
subprocess: [{ command: string; cwd?: string }, [string, string]];
3535
saveFile: [{ filepath: string }, void];
3636
fileExists: [{ filepath: string }, boolean];

core/protocol/messenger/reverseMessageIde.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class ReverseMessageIde {
163163
});
164164

165165
this.on("getFileResults", (data) => {
166-
return this.ide.getFileResults(data.pattern);
166+
return this.ide.getFileResults(data.pattern, data.maxResults);
167167
});
168168

169169
this.on("getProblems", (data) => {

core/tools/definitions/globSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const globSearchTool: Tool = {
1212
group: BUILT_IN_GROUP_NAME,
1313
function: {
1414
name: BuiltInToolNames.FileGlobSearch,
15-
description: "Search for files in the project",
15+
description:
16+
"Search for files in the project. Output may be truncated; use targeted patterns",
1617
parameters: {
1718
type: "object",
1819
required: ["pattern"],
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import { ToolImpl } from ".";
2+
import { ContextItem } from "../..";
23

4+
const MAX_AGENT_GLOB_RESULTS = 100;
35
export const fileGlobSearchImpl: ToolImpl = async (args, extras) => {
4-
const results = await extras.ide.getFileResults(args.pattern);
5-
return [
6+
const results = await extras.ide.getFileResults(
7+
args.pattern,
8+
MAX_AGENT_GLOB_RESULTS,
9+
);
10+
const contextItems: ContextItem[] = [
611
{
712
name: "File results",
813
description: "Results from file glob search",
914
content: results.join("\n"),
1015
},
1116
];
17+
18+
// In case of truncation, add a warning
19+
if (results.length === MAX_AGENT_GLOB_RESULTS) {
20+
contextItems.push({
21+
name: "Truncation warning",
22+
description: "Inform the model that results were truncated",
23+
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`,
24+
});
25+
}
26+
27+
return contextItems;
1228
};

core/util/filesystem.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ class FileSystemIde implements IDE {
238238
return "";
239239
}
240240

241-
async getFileResults(pattern: string): Promise<string[]> {
241+
async getFileResults(
242+
pattern: string,
243+
maxResults?: number,
244+
): Promise<string[]> {
242245
return [];
243246
}
244247

docs/docs/agent/how-it-works.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Continue includes several built-in tools which provide the model access to IDE f
3131
- **Read file** (`builtin_read_file`): read the contents of a file within the project
3232
- **Read currently open file** (`builtin_read_currently_open_file`): read the contents of the currently open file
3333
- **Create new file** (`builtin_create_new_file`): Create a new file within the project, with path and contents specified by the model
34-
- **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)
34+
- **Exact search** (`builtin_exact_search`): perform a `ripgrep` search within the project
35+
- **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.
3536
- **Run terminal command** (`builtin_run_terminal_command`): run a terminal command from the workspace root
3637
- **Search web** (`builtin_search_web`): Perform a web search to get top results
3738
- **View diff** (`builtin_view_diff`): View the current working git diff

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class IdeProtocolClient(
365365
dataElement.toString(),
366366
GetFileResultsParams::class.java
367367
)
368-
val results = ide.getFileResults(params.pattern)
368+
val results = ide.getFileResults(params.pattern, params.maxResults)
369369
respond(results)
370370
}
371371

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,26 @@ class IntelliJIDE(
315315
return getOpenFiles()
316316
}
317317

318-
override suspend fun getFileResults(pattern: String): List<String> {
318+
override suspend fun getFileResults(pattern: String, maxResults: Int?): List<String> {
319319
val ideInfo = this.getIdeInfo()
320320
if (ideInfo.remoteName == "local") {
321321
try {
322-
val command = GeneralCommandLine(
322+
var commandArgs = mutableListOf<String>(
323323
ripgrep,
324324
"--files",
325325
"--iglob",
326326
pattern,
327327
"--ignore-file",
328328
".continueignore",
329329
"--ignore-file",
330-
".gitignore",
330+
".gitignore"
331331
)
332+
if (maxResults != null) {
333+
commandArgs.add("--max-count")
334+
commandArgs.add(maxResults.toString())
335+
}
336+
337+
val command = GeneralCommandLine(commandArgs)
332338

333339
command.setWorkDirectory(project.basePath)
334340
val results = ExecUtil.execAndGetOutput(command).stdout

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ide.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typealias getTagsParams = String
2323

2424
data class GetSearchResultsParams(val query: String, val maxResults: Int?)
2525

26-
data class GetFileResultsParams(val pattern: String)
26+
data class GetFileResultsParams(val pattern: String, val maxResults: Int?)
2727

2828
data class SaveFileParams(val filepath: String)
2929

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ interface IDE {
159159

160160
suspend fun getSearchResults(query: String, maxResults: Int?): String
161161

162-
suspend fun getFileResults(pattern: String): List<String>
162+
suspend fun getFileResults(pattern: String, maxResults: Int?): List<String>
163163

164164
// Note: This should be a `Pair<String, String>` but we use `List<Any>` because the keys of `Pair`
165165
// will serialize to `first and `second` rather than `0` and `1` like in JavaScript

extensions/vscode/src/VsCodeIde.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,10 @@ class VsCodeIde implements IDE {
433433
});
434434
}
435435

436-
async getFileResults(pattern: string): Promise<string[]> {
437-
const MAX_FILE_RESULTS = 200;
436+
async getFileResults(
437+
pattern: string,
438+
maxResults?: number,
439+
): Promise<string[]> {
438440
if (vscode.env.remoteName) {
439441
// TODO better tests for this remote search implementation
440442
// throw new Error("Ripgrep not supported, this workspace is remote");
@@ -501,7 +503,7 @@ class VsCodeIde implements IDE {
501503
const results = await vscode.workspace.findFiles(
502504
pattern,
503505
ignoreGlobs.size ? `{${ignoreGlobsArray.join(",")}}` : null,
504-
MAX_FILE_RESULTS,
506+
maxResults,
505507
);
506508
return results.map((result) => vscode.workspace.asRelativePath(result));
507509
} else {
@@ -515,12 +517,20 @@ class VsCodeIde implements IDE {
515517
".continueignore",
516518
"--ignore-file",
517519
".gitignore",
520+
...(maxResults ? ["--max-count", String(maxResults)] : []),
518521
]);
519522

520523
results.push(dirResults);
521524
}
522525

523-
return results.join("\n").split("\n").slice(0, MAX_FILE_RESULTS);
526+
const allResults = results.join("\n").split("\n");
527+
if (maxResults) {
528+
// In the case of multiple workspaces, maxResults will be applied to each workspace
529+
// And then the combined results will also be truncated
530+
return allResults.slice(0, maxResults);
531+
} else {
532+
return allResults;
533+
}
524534
}
525535
}
526536

extensions/vscode/src/extension/VsCodeMessenger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class VsCodeMessenger {
324324
return ide.getSearchResults(msg.data.query, msg.data.maxResults);
325325
});
326326
this.onWebviewOrCore("getFileResults", async (msg) => {
327-
return ide.getFileResults(msg.data.pattern);
327+
return ide.getFileResults(msg.data.pattern, msg.data.maxResults);
328328
});
329329
this.onWebviewOrCore("subprocess", async (msg) => {
330330
return ide.subprocess(msg.data.command, msg.data.cwd);

0 commit comments

Comments
 (0)