mcpField
M
mgrep-code-search

mgrep-code-search

github.com/intellectronica开发298621 次安装27 周前更新
代码仓库

关于 mgrep-code-search

mgrep-code-search 是一项技能,可用自然语言在代码及其他仓库文件中进行语义搜索。它帮助开发者按概念定位实现,适合探索陌生或复杂的代码库。

主要功能

  1. 01自然语言语义搜索
  2. 02搜索代码、文本、PDF 和图片
  3. 03索引并跟踪仓库变更
  4. 04按路径和结果数量筛选
  5. 05显示匹配内容或 AI 综合答案

适用场景

  1. 01定位某项功能的实现位置
  2. 02探索陌生代码库
  3. 03在嵌套目录中查找概念

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/intellectronica/agent-skills --skill mgrep-code-search

安装后在 Claude Code 中输入/mgrep-code-search确认已加载。

详细介绍

mgrep 代码搜索

概述

mgrep 是一款语义搜索工具,支持使用自然语言查询代码、文本、PDF 和图像。它尤其适用于探索较大或复杂的代码库,因为传统的模式匹配在这类场景中往往力有不逮。

何时使用此技能

在以下情况下使用 mgrep:

  • 代码库中包含超过 30 个未被 git 忽略的文件
  • 目录结构存在嵌套
  • 搜索概念、功能或意图,而不是精确字符串
  • 探索不熟悉的代码库
  • 需要了解某项内容“在哪里”或“如何”实现

在以下情况下使用传统的 grep/ripgrep:

  • 搜索精确模式或符号
  • 基于正则表达式进行重构
  • 跟踪特定的函数名或变量名

快速入门

建立索引

搜索前,启动监听器为仓库建立索引:

bunx @mixedbread/mgrep watch

watch 命令会为仓库建立索引,并持续同步文件变更。它会遵循 .gitignore 和 .mgrepignore 中的模式。

搜索
bunx @mixedbread/mgrep "your natural language query" [path]

搜索命令

基本搜索
bunx @mixedbread/mgrep "where is authentication configured?"
bunx @mixedbread/mgrep "how do we handle errors in API calls?" src/
bunx @mixedbread/mgrep "database connection setup" src/lib
搜索选项
选项说明
-m <count>最大结果数(默认值:10)
-c, --content显示完整结果内容
-a, --answer生成由 AI 提供的结果综合分析
-s, --sync搜索前更新索引
--no-rerank禁用相关性优化
使用选项的示例
# Get more results
bunx @mixedbread/mgrep -m 25 "user authentication flow"

# Show full content of matches
bunx @mixedbread/mgrep -c "error handling patterns"

# Get an AI-synthesised answer
bunx @mixedbread/mgrep -a "how does the caching layer work?"

# Sync index before searching
bunx @mixedbread/mgrep -s "payment processing" src/services

工作流

  1. 启动监听器(每个会话启动一次,或在文件发生较大变更时启动):

    bunx @mixedbread/mgrep watch
    
  2. 进行语义搜索:

    bunx @mixedbread/mgrep "what you're looking for" [optional/path]
    
  3. 根据需要使用路径约束或选项进行优化:

    bunx @mixedbread/mgrep -m 20 -c "refined query" src/specific/directory
    

环境变量

通过环境变量配置默认值:

变量用途
MGREP_MAX_COUNT默认结果数量上限
MGREP_CONTENT启用内容显示(1/true)
MGREP_ANSWER启用 AI 综合分析(1/true)
MGREP_SYNC搜索前同步(1/true)

重要说明

  • 始终使用 bunx @mixedbread/mgrep 运行命令(不要使用 npm/npx 或直接安装)
  • 搜索前运行 bunx @mixedbread/mgrep watch,确保索引为最新状态
  • mgrep 会自动遵循 .gitignore 中的模式
  • 如需添加其他排除项,请创建 .mgrepignore

评论

支持 Markdown