Search Hierarchy

作者 parcadeid07ff4b06b62无许可证3.9K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库8个月前更新

Search Tool Hierarchy

AI 生成的概览

指导代理选择最省 token 的代码搜索工具:AST-grep、LEANN、Grep 或 Read。

功能
该技能提供决策树和 token 效率对比,用于在四种代码搜索工具间选择:AST-grep 用于结构模式,LEANN 用于语义问题,Grep 用于字面标识符,Read 用于完整上下文。它列出该做与不该做的事项、示例命令,以及先运行 AST-grep、只读取最佳匹配的最优流程。它还描述了一个名为 grep-to-leann.sh 的钩子,用于检测查询类型并阻止或重定向查询到建议的工具。
适用场景
在搜索代码库并需要为某类查询决定运行哪个搜索工具时使用。它面向希望避免宽泛 Grep 或过早读取文件、从而减少 token 消耗的代理。
运行要求
该技能不附带脚本,仅为说明文档。它引用了外部工具(AST-grep、LEANN、Grep、Read)以及一个名为 grep-to-leann.sh 的钩子,这些均未包含在内。

Search Tool Hierarchy

Use the most token-efficient search tool for each query type.

Decision Tree

Query Type?├── STRUCTURAL (code patterns)│   → AST-grep (~50 tokens output)│   Examples: "def foo", "class Bar", "import X", "@decorator"│├── SEMANTIC (conceptual questions)│   → LEANN (~100 tokens if path-only)│   Examples: "how does auth work", "find error handling patterns"│├── LITERAL (exact identifiers)│   → Grep (variable output)│   Examples: "TemporalMemory", "check_evocation", regex patterns│└── FULL CONTEXT (need complete understanding)    → Read (1500+ tokens)    Last resort after finding the right file

Token Efficiency Comparison

ToolOutput SizeBest For
AST-grep~50 tokensFunction/class definitions, imports, decorators
LEANN~100 tokensConceptual questions, architecture, patterns
Grep~200-2000Exact identifiers, regex, file paths
Read~1500+Full understanding after finding the file

Hook Enforcement

The grep-to-leann.sh hook automatically:

  1. Detects query type (structural/semantic/literal)
  2. Blocks and suggests AST-grep for structural queries
  3. Blocks and suggests LEANN for semantic queries
  4. Allows literal patterns through to Grep

DO

  • Start with AST-grep for code structure questions
  • Use LEANN for "how does X work" questions
  • Use Grep only for exact identifier matches
  • Read files only after finding them via search

DON'T

  • Use Grep for conceptual questions (returns nothing)
  • Read files before knowing which ones are relevant
  • Use Read when AST-grep would give file:line
  • Ignore hook suggestions

Examples

bash
# STRUCTURAL → AST-grepast-grep --pattern "async def $FUNC($$$):" --lang python
# SEMANTIC → LEANNleann search opc-dev "how does authentication work" --top-k 3
# LITERAL → GrepGrep pattern="check_evocation" path=opc/scripts
# FULL CONTEXT → Read (after finding file)Read file_path=opc/scripts/z3_erotetic.py

Optimal Flow

1. AST-grep: "Find async functions" → 3 file:line matches2. Read: Top match only → Full understanding3. Skip: 4 irrelevant files → 6000 tokens saved

来源与署名

来源:parcadei/continuous-claude-v3位于.claude/skills/archive/search-hierarchy提交d07ff4b

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架