From c2e4e8c800bfb6e287808843d8175e17a7d6d0b6 Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Sat, 25 Apr 2026 21:31:17 +0800 Subject: [PATCH] feat(lsp): add LSP reminder to grep/readfile tool descriptions When LSP is enabled, the model often chose grep or readfile instead of LSP for code intelligence queries. Now the competing tools' descriptions include a note reminding the model to use the LSP tool for definitions, references, symbols, hover, diagnostics, etc. This "push-pull" approach: - System prompt pushes toward LSP (top-level priority instruction) - Grep/ReadFile descriptions pull away from code intelligence usage --- packages/core/src/tools/grep.ts | 5 ++++- packages/core/src/tools/read-file.ts | 5 ++++- packages/core/src/tools/ripGrep.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tools/grep.ts b/packages/core/src/tools/grep.ts index 53500022f..25bb1be1b 100644 --- a/packages/core/src/tools/grep.ts +++ b/packages/core/src/tools/grep.ts @@ -564,10 +564,13 @@ export class GrepTool extends BaseDeclarativeTool { static readonly Name = ToolNames.GREP; constructor(private readonly config: Config) { + const lspNote = config.isLspEnabled() + ? '\n - IMPORTANT: An LSP tool is available. For code intelligence queries (finding definitions, references, implementations, symbols, hover info, diagnostics, call hierarchy), use the "lsp" tool instead of Grep. Grep should only be used for text pattern searches, NOT for code navigation or symbol lookups.\n' + : ''; super( GrepTool.Name, ToolDisplayNames.GREP, - 'A powerful search tool for finding patterns in files\n\n Usage:\n - ALWAYS use Grep for search tasks. NEVER invoke `grep` or `rg` as a Bash command. The Grep tool has been optimized for correct permissions and access.\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx")\n - Case-insensitive by default\n - Use Agent tool for open-ended searches requiring multiple rounds\n', + `A powerful search tool for finding patterns in files\n\n Usage:\n - ALWAYS use Grep for search tasks. NEVER invoke \`grep\` or \`rg\` as a Bash command. The Grep tool has been optimized for correct permissions and access.${lspNote}\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx")\n - Case-insensitive by default\n - Use Agent tool for open-ended searches requiring multiple rounds\n`, Kind.Search, { properties: { diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts index c05740b52..683f18667 100644 --- a/packages/core/src/tools/read-file.ts +++ b/packages/core/src/tools/read-file.ts @@ -211,10 +211,13 @@ export class ReadFileTool extends BaseDeclarativeTool< static readonly Name: string = ToolNames.READ_FILE; constructor(private config: Config) { + const lspNote = config.isLspEnabled() + ? ' Note: An LSP tool is available for code intelligence. For finding definitions, references, implementations, symbols, hover info, diagnostics, or call hierarchy, prefer the "lsp" tool over reading files manually.' + : ''; super( ReadFileTool.Name, ToolDisplayNames.READ_FILE, - `Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), PDF files, and Jupyter notebooks (.ipynb). For text files, it can read specific line ranges. For PDF files, use the 'pages' parameter to extract specific page ranges as text (e.g. '1-5'). Max 20 pages per request. This tool can read Jupyter notebooks (.ipynb) and returns structured cell content with outputs.`, + `Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), PDF files, and Jupyter notebooks (.ipynb). For text files, it can read specific line ranges. For PDF files, use the 'pages' parameter to extract specific page ranges as text (e.g. '1-5'). Max 20 pages per request. This tool can read Jupyter notebooks (.ipynb) and returns structured cell content with outputs.${lspNote}`, Kind.Read, { properties: { diff --git a/packages/core/src/tools/ripGrep.ts b/packages/core/src/tools/ripGrep.ts index 7cbf33677..677ca026f 100644 --- a/packages/core/src/tools/ripGrep.ts +++ b/packages/core/src/tools/ripGrep.ts @@ -324,10 +324,13 @@ export class RipGrepTool extends BaseDeclarativeTool< static readonly Name = ToolNames.GREP; constructor(private readonly config: Config) { + const lspNote = config.isLspEnabled() + ? '\n - IMPORTANT: An LSP tool is available. For code intelligence queries (finding definitions, references, implementations, symbols, hover info, diagnostics, call hierarchy), use the "lsp" tool instead of Grep. Grep should only be used for text pattern searches, NOT for code navigation or symbol lookups.\n' + : ''; super( RipGrepTool.Name, 'Grep', - 'A powerful search tool built on ripgrep\n\n Usage:\n - ALWAYS use Grep for search tasks. NEVER invoke `grep` or `rg` as a Bash command. The Grep tool has been optimized for correct permissions and access.\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx")\n - Use Agent tool for open-ended searches requiring multiple rounds\n - Pattern syntax: Uses ripgrep (not grep) - special regex characters need escaping (use `interface\\{\\}` to find `interface{}` in Go code)\n', + `A powerful search tool built on ripgrep\n\n Usage:\n - ALWAYS use Grep for search tasks. NEVER invoke \`grep\` or \`rg\` as a Bash command. The Grep tool has been optimized for correct permissions and access.${lspNote}\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx")\n - Use Agent tool for open-ended searches requiring multiple rounds\n - Pattern syntax: Uses ripgrep (not grep) - special regex characters need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)\n`, Kind.Search, { properties: {