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 從公開儲存庫中收錄這些內容。

檢舉或申請下架