From c3dba47bcda10bbcd72010c177afa8fd301e87e1 Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Wed, 21 May 2025 13:11:52 -0400 Subject: feat: add codebase exploration tools for agent assistance Add three new agent tools to improve navigation and understanding of the codebase: FileContentTool: retrieves complete content of specified files (max 3) FileNamesTool: lists all available files in the codebase CodebaseSummarySearchTool: performs semantic search across file summaries --- .../chatbot/tools/CodebaseSummarySearchTool.ts | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts (limited to 'src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts') diff --git a/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts b/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts new file mode 100644 index 000000000..5fdc52375 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts @@ -0,0 +1,75 @@ +import { Observation } from '../types/types'; +import { ParametersType, ToolInfo } from '../types/tool_types'; +import { Vectorstore } from '../vectorstore/Vectorstore'; +import { BaseTool } from './BaseTool'; + +const codebaseSummarySearchToolParams = [ + { + name: 'query', + type: 'string[]', + description: 'HIGHLY detailed (MANY SENTENCES) descriptions of the code files you want to find in the codebase.', + required: true, + }, + { + name: 'top_k', + type: 'number', + description: 'Number of top matching files to return. Default is 5.', + required: false, + }, +] as const; + +type CodebaseSummarySearchToolParamsType = typeof codebaseSummarySearchToolParams; + +const codebaseSummarySearchToolInfo: ToolInfo = { + name: 'codebaseSummarySearch', + description: 'Searches the Dash codebase for files that match a semantic query. Returns a list of the most relevant files with their summaries to help understand the codebase structure.', + citationRules: `When using the CodebaseSummarySearchTool: +1. Present results clearly, showing filepaths and their summaries +2. Use the file summaries to provide context about the codebase organization +3. The results can be used to identify relevant files for deeper inspection`, + parameterRules: codebaseSummarySearchToolParams, +}; + +export class CodebaseSummarySearchTool extends BaseTool { + constructor(private vectorstore: Vectorstore) { + super(codebaseSummarySearchToolInfo); + } + + async execute(args: ParametersType): Promise { + console.log(`Executing codebase summary search with query: "${args.query}"`); + + // Use the vectorstore's searchFileSummaries method + const topK = args.top_k || 5; + const results: { filepath: string; summary: string; score?: number | undefined }[] = []; + for (const query of args.query) { + const result = await this.vectorstore.searchFileSummaries(query, topK); + results.push(...result); + } + + if (results.length === 0) { + return [ + { + type: 'text', + text: `No files matching the query "${args.query}" were found in the codebase.`, + }, + ]; + } + + // Format results as observations + const formattedResults: Observation[] = [ + { + type: 'text', + text: `Found ${results.length} file(s) matching the query "${args.query}":\n\n`, + }, + ]; + + results.forEach((result, index) => { + formattedResults.push({ + type: 'text', + text: `File #${index + 1}: ${result.filepath}\n` + `Relevance Score: ${result.score?.toFixed(4) || 'N/A'}\n` + `Summary: ${result.summary}\n\n`, + }); + }); + + return formattedResults; + } +} -- cgit v1.2.3-70-g09d2