Codesearch 工具
Codesearch 工具用于语义化代码搜索。
概述
Codesearch 工具允许 AI 助手进行语义化代码搜索。它支持:
- 自然语言查询
- 代码片段搜索
- 跨项目搜索
定义位置
packages/opencode/src/tool/codesearch.ts
参数说明
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | 是 | 搜索查询 |
TypeScript 类型定义
export type CodesearchInput = {
query: string
}
export type CodesearchOutput = {
title: string
output: string
metadata: {
results?: CodeResult[]
}
}
典型使用场景
搜索代码模式
await CodeSearchTool.execute({
query: "how to implement authentication in React",
}, ctx)
搜索函数用法
await CodeSearchTool.execute({
query: "useEffect hook with cleanup function",
}, ctx)
相关文档
- Grep - 文本内容搜索
- Tool System - Tool 系统实现机制