code_search
code_search 是给 AI 用来快速 grep 代码的工具——比 unified_search.code_search 更轻、调用更快,专攻两个场景:
| scope | 找什么 | 后端 |
|---|
scope="sandbox" | 当前会话 sandbox 里临时下载/生成的代码 | ripgrep + ast-grep |
scope="kb" | 知识库里零索引档 / 轻索引档的代码(不需要等索引) | ripgrep + ast-grep over 本地缓存 |
重索引档的代码搜索(trigram、跨仓 navigate、向量语义)走 unified_search.code_search。code_search 不做这些。
| 场景 | 用哪个 |
|---|
| AI 刚把一个仓库下载到 sandbox 里,要快速找一段代码 | code_search(scope="sandbox") |
| 知识库里挂了一个零/轻索引代码库,文本/AST grep | code_search(scope="kb", kb_ids=[...]) |
| 跨仓查"这个函数被谁调用"——需要语义图 | unified_search.code_search(mode="navigate") |
| 用自然语言找代码——需要向量召回 | unified_search.code_search(mode="semantic") |
| mode | 引擎 | 适合 |
|---|
text | ripgrep | 字面、正则、文件名 |
ast | ast-grep | 结构匹配("所有 try-except 没 log 的") |