AgentSkillsCN

Tool Priority

在选择搜索工具(LSP、grep、glob)时,或需要查阅工具参考时使用——详尽介绍各类工具的适用场景与详细语法

SKILL.md
--- frontmatter
description: Use when choosing between search tools (LSP, grep, glob) or need tool reference - covers when to use each tool and detailed syntax

Tool Priority Skill

Priority Order

LSP tools → grep → glob

  1. LSP tools - Semantic code intelligence (10 tools)
  2. grep - Text search (logs, config, code patterns, strings)
  3. glob - File discovery by name pattern
  4. read, edit, write - File operations

Rule: Always read before edit to verify content.

Choosing the Right Tool

Ask: "Am I looking for semantic understanding or just text?"

Code Understanding (Use LSP)

NeedToolExample
Symbol type infolsp_lsp_hoverType signature at cursor
Definition jumplsp_lsp_goto_definitionSource location
All usageslsp_lsp_find_referencesBefore refactoring
File structurelsp_lsp_document_symbolsWhat functions/classes in this file?
Safe renamelsp_lsp_renameUpdate symbol across codebase
Workspace searchlsp_lsp_workspace_symbolsWhere is UserService defined?

Text Search (Use grep)

NeedToolExample pattern
Function callsgrepfunctionName\(
Import statementsgrepimport.*from.*module
Error messagesgrepFATAL|ERROR
Config valuesgrepAPI_KEY
TODO commentsgrepTODO|FIXME
Hook usagegrepuseState(
Debug logsgrepconsole\.log\(

Workflow Pattern

code
# Step 1: Find it
grep "functionName" src/

# Step 2: Understand it
read src/file.ts
lsp_lsp_document_symbols(filePath="src/file.ts", line=1, character=1)

# Step 3: Trace it
lsp_lsp_goto_definition(filePath="src/file.ts", line=42, character=10)
lsp_lsp_find_references(filePath="src/file.ts", line=42, character=10)

# Step 4: Modify it (if needed)
lsp_lsp_hover(filePath="src/file.ts", line=42, character=10)

LSP Tools Reference

Semantic code intelligence via Language Server Protocol. Uses lsp_lsp_* prefix (built-in experimental).

Navigation & Understanding

ToolPurposeWhen to Use
lsp_lsp_hover(filePath, line, character)Type info and docs at cursor"What type is this variable?"
lsp_lsp_goto_definition(filePath, line, character)Jump to where symbol is defined"Where is this function defined?"
lsp_lsp_find_references(filePath, line, character)Find all usages of a symbol"What uses this function?"
lsp_lsp_document_symbols(filePath)File outline (classes, functions)"What's in this file?"
lsp_lsp_workspace_symbols(query, filePath)Fuzzy search symbols across workspace"Where is UserService defined?"

Diagnostics

ToolPurposeWhen to Use
lsp_lsp_diagnostics(filePath, severity?)Errors/warnings from language server"Are there type errors?"

Refactoring

ToolPurposeWhen to Use
lsp_lsp_rename(filePath, line, character, newName)Rename symbol across codebase"Rename this function safely"
lsp_lsp_code_actions(filePath, startLine, startChar, endLine, endChar)Get available refactorings"What refactorings are available?"
lsp_lsp_code_action_apply(...)Apply a specific code actionExecute chosen refactoring
lsp_lsp_organize_imports(filePath)Clean up and sort imports"Fix imports"

Caveat: LSP tools modify files directly. Re-read files before further edits.

grep Reference

Fast, text-based search using ripgrep.

Basic Patterns

bash
# Find function definitions
grep "function\|const.*=.*(" src/

# Find imports
grep "import.*from" src/

# Find React hooks
grep "useState\|useEffect" src/

# Find console logs
grep "console\.log" src/

# Search for errors
grep "Error\|Exception\|Throw" src/

# Multiple patterns
grep -e "TODO" -e "FIXME" src/

# Case insensitive
grep -i "test" src/

# Specific file types
grep -r "API_KEY" --include="*.ts" --include="*.js"

grep vs LSP

ScenarioUseWhy
"Find all X"grepFast text search, everything including comments
"Where is X used?"lsp_lsp_find_referencesSemantic, only code usage, tracks dependencies
"What type is X?"lsp_lsp_hoverType system intelligence
"Find TODOs"grepText search across all files
"Rename X"lsp_lsp_renameSafe semantic refactoring

Common Gotchas

grep finds everything:

bash
grep "fetchUser"  # Matches: function fetchUser(), "fetchUser" string, // fetchUser comment

LSP finds only code:

bash
lsp_lsp_find_references  # Only actual usages in code, not strings/comments

When to use grep first:

  • Quick exploration ("are there any X?")
  • Finding error patterns, logs, configs
  • Searching across file types (JSON, YAML, etc.)

When to use LSP first:

  • Understanding code structure
  • Before refactoring
  • Tracing dependencies
  • Getting type information

glob Reference

Find files by pattern.

bash
# All TypeScript files
glob "**/*.ts"

# All test files
glob "**/*.test.ts"

# Specific directory
glob "src/**/*.ts"

# Multiple patterns
glob ["src/**/*.ts", "tests/**/*.ts"]

Research Tools

ToolUse When
context7Library docs (try first). Fast, external APIs.
websearchDocs not in Context7, recent releases, troubleshooting.
codesearchReal implementation patterns from GitHub.
webfetchSpecific URL user provided.