Elffuss BraidHub

kikocis/continue public

Merge pull request #6360 from tingwai/tingwai/add-at-codebase-to-experimental-tools

Add @codebase as experimental tool for agent mode
Changeset54bc82ab2ee9f440b8c7bdcc120e640e1b42d28896f0c34603fa727444c8c8f5
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-01 11:40 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-01 11:40 -07:00
Parents960dd3a6efa1, afb5df1f558f

Browse the files at this changeset

5 files changed

modified core/tools/builtIn.ts +1 −0
@@ -13,6 +13,7 @@
1313 CreateRuleBlock = "builtin_create_rule_block",
1414 RequestRule = "builtin_request_rule",
1515 FetchUrlContent = "builtin_fetch_url_content",
16+ CodebaseTool = "builtin_codebase",
1617
1718 // excluded from allTools for now
1819 ViewRepoMap = "builtin_view_repo_map",
modified core/tools/callTool.ts +3 −0
@@ -3,6 +3,7 @@
33 import { canParseUrl } from "../util/url";
44 import { BuiltInToolNames } from "./builtIn";
55
6+import { codebaseToolImpl } from "./implementations/codebaseTool";
67 import { createNewFileImpl } from "./implementations/createNewFile";
78 import { createRuleBlockImpl } from "./implementations/createRuleBlock";
89 import { fetchUrlContentImpl } from "./implementations/fetchUrlContent";
@@ -164,6 +165,8 @@
164165 return await createRuleBlockImpl(args, extras);
165166 case BuiltInToolNames.RequestRule:
166167 return await requestRuleImpl(args, extras);
168+ case BuiltInToolNames.CodebaseTool:
169+ return await codebaseToolImpl(args, extras);
167170 default:
168171 throw new Error(`Tool "${functionName}" not found`);
169172 }
added core/tools/definitions/codebaseTool.ts +29 −0
@@ -0,0 +1,29 @@
1+import { Tool } from "../..";
2+import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3+
4+export const codebaseTool: Tool = {
5+ type: "function",
6+ displayTitle: "Codebase Search",
7+ wouldLikeTo: "search the codebase for: {{{ query }}}",
8+ isCurrently: "searching the codebase for: {{{ query }}}",
9+ hasAlready: "searched the codebase for: {{{ query }}}",
10+ readonly: true,
11+ isInstant: false,
12+ group: BUILT_IN_GROUP_NAME,
13+ function: {
14+ name: BuiltInToolNames.CodebaseTool,
15+ description:
16+ "Use this tool to semantically search through the codebase and retrieve relevant code snippets based on a natural language query. This helps find relevant code context for understanding or working with the codebase.",
17+ parameters: {
18+ type: "object",
19+ required: ["query"],
20+ properties: {
21+ query: {
22+ type: "string",
23+ description:
24+ "Natural language description of what you're looking for in the codebase (e.g., 'authentication logic', 'database connection setup', 'error handling')",
25+ },
26+ },
27+ },
28+ },
29+};
added core/tools/implementations/codebaseTool.ts +61 −0
@@ -0,0 +1,61 @@
1+import { ToolImpl } from ".";
2+import { RangeInFile } from "../..";
3+import { retrieveContextItemsFromEmbeddings } from "../../context/retrieval/retrieval";
4+
5+export const codebaseToolImpl: ToolImpl = async (args, extras) => {
6+ if (!args.query || args.query.trim() === "") {
7+ return [
8+ {
9+ name: "Error",
10+ description: "Codebase search error",
11+ content: "Query parameter is required and cannot be empty.",
12+ },
13+ ];
14+ }
15+
16+ try {
17+ const contextExtras = {
18+ config: extras.config,
19+ fullInput: args.query,
20+ embeddingsProvider: extras.config.selectedModelByRole.embed,
21+ reranker: extras.config.selectedModelByRole.rerank,
22+ llm: extras.llm,
23+ ide: extras.ide,
24+ selectedCode: [] as RangeInFile[],
25+ fetch: extras.fetch,
26+ };
27+
28+ // Use the existing retrieval function to get context items
29+ const results = await retrieveContextItemsFromEmbeddings(
30+ contextExtras,
31+ undefined,
32+ undefined,
33+ );
34+
35+ // If no results found, return helpful message
36+ if (results.length === 0) {
37+ return [
38+ {
39+ name: "No Results",
40+ description: "Codebase search",
41+ content: `No relevant code found for query: "${args.query}". This could mean:
42+- The codebase hasn't been indexed yet
43+- No code matches the search criteria
44+- Embeddings provider is not configured
45+
46+Try re-indexing the codebase or using a more specific query.`,
47+ },
48+ ];
49+ }
50+
51+ return results;
52+ } catch (error) {
53+ return [
54+ {
55+ name: "Error",
56+ description: "Codebase search error",
57+ content: `Failed to search codebase: ${error instanceof Error ? error.message : String(error)}`,
58+ },
59+ ];
60+ }
61+};
modified core/tools/index.ts +7 −1
@@ -1,4 +1,5 @@
11 import { ConfigDependentToolParams, IDE, Tool } from "..";
2+import { codebaseTool } from "./definitions/codebaseTool";
23 import { createNewFileTool } from "./definitions/createNewFile";
34 import { createRuleBlock } from "./definitions/createRuleBlock";
45 import { editFileTool } from "./definitions/editFile";
@@ -37,7 +38,12 @@
3738 ): Tool[] => [
3839 requestRuleTool(params),
3940 ...(params.enableExperimentalTools
40- ? [searchAndReplaceInFileTool, viewRepoMapTool, viewSubdirectoryTool]
41+ ? [
42+ searchAndReplaceInFileTool,
43+ viewRepoMapTool,
44+ viewSubdirectoryTool,
45+ codebaseTool,
46+ ]
4147 : [editFileTool]),
4248 ];
4349