search-router

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Search Tool Router

搜索工具路由

Use the most token-efficient search tool for each query type.
为每种查询类型选用最节省Token的搜索工具。

When to Use

适用场景

  • Searching for code patterns
  • Finding where something is implemented
  • Looking for specific identifiers
  • Understanding how code works
  • 搜索代码模式
  • 查找功能实现位置
  • 定位特定标识符
  • 理解代码工作原理

Decision Tree

决策树

Query Type?
├── CODE EXPLORATION (symbols, call chains, data flow)
│   → TLDR Search - 95% token savings
│   DEFAULT FOR ALL CODE SEARCH - use instead of Grep
│   Examples: "spawn_agent", "DataPoller", "redis usage"
│   Command: tldr search "query" .
├── STRUCTURAL (AST patterns)
│   → AST-grep (/ast-grep-find) - ~50 tokens output
│   Examples: "def foo", "class Bar", "import X", "@decorator"
├── SEMANTIC (conceptual questions)
│   → TLDR Semantic - 5-layer embeddings (P6)
│   Examples: "how does auth work", "find error handling patterns"
│   Command: tldr semantic search "query"
├── LITERAL (exact text, regex)
│   → Grep tool - LAST RESORT
│   Only when TLDR/AST-grep don't apply
│   Examples: error messages, config values, non-code text
└── FULL CONTEXT (need complete understanding)
    → Read tool - 1500+ tokens
    Last resort after finding the right file
查询类型?
├── 代码探索(符号、调用链、数据流)
│   → TLDR Search - 节省95% Token
│   所有代码搜索的默认工具 - 替代Grep使用
│   示例:"spawn_agent"、"DataPoller"、"redis usage"
│   命令:tldr search "query" .
├── 结构型(AST模式)
│   → AST-grep (/ast-grep-find) - 约50个Token输出
│   示例:"def foo"、"class Bar"、"import X"、"@decorator"
├── 语义型(概念性问题)
│   → TLDR Semantic - 5层嵌入(P6)
│   示例:"how does auth work"、"find error handling patterns"
│   命令:tldr semantic search "query"
├── 字面量(精确文本、正则表达式)
│   → Grep工具 - 最后选择
│   仅当TLDR/AST-grep不适用时使用
│   示例:错误信息、配置值、非代码文本
└── 完整上下文(需要全面理解)
    → Read工具 - 1500+ Token
    找到目标文件后的最后选择

Token Efficiency Comparison

Token效率对比

ToolOutput SizeBest For
TLDR~50-500DEFAULT: Code symbols, call graphs, data flow
TLDR Semantic~100-300Conceptual queries (P6, embedding-based)
AST-grep~50 tokensFunction/class definitions, imports, decorators
Grep~200-2000LAST RESORT: Non-code text, regex
Read~1500+Full understanding after finding the file
工具输出大小最佳适用场景
TLDR~50-500默认:代码符号、调用图、数据流
TLDR Semantic~100-300概念性查询(基于P6嵌入)
AST-grep~50 tokens函数/类定义、导入语句、装饰器
Grep~200-2000最后选择:非代码文本、正则表达式
Read~1500+找到文件后全面理解内容

Examples

示例

bash
undefined
bash
undefined

CODE EXPLORATION → TLDR (DEFAULT)

代码探索 → TLDR(默认)

tldr search "spawn_agent" . tldr search "redis" . --layer call_graph
tldr search "spawn_agent" . tldr search "redis" . --layer call_graph

STRUCTURAL → AST-grep

结构型 → AST-grep

/ast-grep-find "async def $FUNC($$$):" --lang python
/ast-grep-find "async def $FUNC($$$):" --lang python

SEMANTIC → TLDR Semantic

语义型 → TLDR Semantic

tldr semantic search "how does authentication work"
tldr semantic search "how does authentication work"

LITERAL → Grep (LAST RESORT - prefer TLDR)

字面量 → Grep(最后选择 - 优先使用TLDR)

Grep pattern="check_evocation" path=opc/scripts
Grep pattern="check_evocation" path=opc/scripts

FULL CONTEXT → Read (after finding file)

完整上下文 → Read(找到文件后)

Read file_path=opc/scripts/z3_erotetic.py
undefined
Read file_path=opc/scripts/z3_erotetic.py
undefined

Optimal Flow

最优流程

1. AST-grep: "Find async functions" → 3 file:line matches
2. Read: Top match only → Full understanding
3. Skip: 4 irrelevant files → 6000 tokens saved
1. AST-grep:"查找异步函数" → 3个文件:行匹配结果
2. Read:仅查看顶部匹配结果 → 全面理解内容
3. 跳过:4个无关文件 → 节省6000个Token

Related Skills

相关技能

  • /tldr-search
    - DEFAULT - Code exploration with 95% token savings
  • /ast-grep-find
    - Structural code search
  • /morph-search
    - Fast text search
  • /tldr-search
    - 默认工具 - 节省95% Token的代码探索工具
  • /ast-grep-find
    - 结构型代码搜索
  • /morph-search
    - 快速文本搜索