关于 grepai-ignore-patterns
grepai-ignore-patterns 说明如何配置 GrepAI 的忽略规则,以控制代码索引包含的文件和目录。适合需要排除测试、生成文件或依赖项,并调整搜索结果范围的开发者。
主要功能
- 01通过配置文件设置忽略规则
- 02支持目录、文件及 glob 模式
- 03自动遵循 .gitignore
- 04可用搜索惩罚替代排除
- 05修改规则后重新索引
适用场景
- 01排除测试代码以聚焦生产代码
- 02跳过生成文件和第三方依赖
- 03通过忽略构建产物缩小索引
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ grepai-skills --skill grepai-ignore-patterns安装后在 Claude Code 中输入/grepai-ignore-patterns确认已加载。
详细介绍
GrepAI 忽略模式
本技能介绍如何配置忽略模式,以便将文件和目录排除在 GrepAI 索引之外。
何时使用此技能
- 从搜索结果中排除测试文件
- 忽略生成的代码或引入的第三方代码
- 通过排除不必要的文件来缩小索引
- 自定义 GrepAI 要索引的文件
忽略模式的工作方式
GrepAI 使用以下两个来源的忽略模式:
.grepai/config.yaml- 自定义定义的模式.gitignore- 自动遵循其中的规则
配置位置
# .grepai/config.yaml
ignore:
- pattern1
- pattern2
模式语法
目录模式
ignore:
# Exact directory name (matches anywhere)
- node_modules
- vendor
- __pycache__
# With trailing slash (explicit directory)
- dist/
- build/
- coverage/
文件模式
ignore:
# Exact filename
- package-lock.json
- yarn.lock
# Wildcard patterns
- "*.min.js"
- "*.min.css"
- "*.map"
- "*.lock"
路径模式
ignore:
# Paths containing substring
- /tests/
- /spec/
- /__tests__/
# Specific paths
- src/generated/
- api/swagger/
Glob 模式
ignore:
# Double star (recursive)
- "**/test/**"
- "**/mock/**"
# Single star (single level)
- "*.test.js"
- "*.spec.ts"
- "*_test.go"
默认忽略模式
GrepAI 的默认配置包含:
ignore:
# Version control
- .git
- .svn
- .hg
# GrepAI itself
- .grepai
# Package managers
- node_modules
- vendor
- .npm
- .yarn
# Build outputs
- target
- dist
- build
- out
# Cache directories
- __pycache__
- .pytest_cache
- .mypy_cache
- .cache
# Framework outputs
- .next
- .nuxt
- .output
常见忽略配置
JavaScript/TypeScript 项目
ignore:
- node_modules
- dist
- build
- coverage
- .nyc_output
- "*.min.js"
- "*.bundle.js"
- "*.map"
- package-lock.json
- yarn.lock
- pnpm-lock.yaml
Go 项目
ignore:
- vendor
- bin
- "*.pb.go" # Protobuf generated
- "*_mock.go" # Mocks
- "mocks/"
- go.sum
Python 项目
ignore:
- __pycache__
- .pytest_cache
- .mypy_cache
- .venv
- venv
- env
- "*.pyc"
- "*.pyo"
- .eggs
- "*.egg-info"
- dist
- build
Rust 项目
ignore:
- target
- Cargo.lock
- "*.rlib"
Java/Kotlin 项目
ignore:
- target
- build
- .gradle
- "*.class"
- "*.jar"
- "*.war"
Monorepo
ignore:
# Common
- node_modules
- dist
- build
- coverage
# Specific packages to exclude
- packages/legacy/
- packages/deprecated/
# Generated
- "**/generated/**"
- "**/__generated__/**"
排除测试文件
若要专注于生产代码:
ignore:
# Test directories
- tests/
- test/
- __tests__/
- spec/
# Test files by pattern
- "*.test.js"
- "*.test.ts"
- "*.spec.js"
- "*.spec.ts"
- "*_test.go"
- "test_*.py"
- "*_test.py"
替代方案: 使用搜索加权来降低测试文件的排名,而非将其排除:
search:
boost:
penalties:
- pattern: /tests/
factor: 0.5
- pattern: _test.
factor: 0.5
排除生成的代码
ignore:
# Generated markers
- "**/generated/**"
- "*.generated.*"
- "*.gen.*"
# Specific generators
- "*.pb.go" # Protobuf
- "*.graphql.ts" # GraphQL codegen
- "*.d.ts" # TypeScript declarations
- "swagger_*.go" # Swagger
- "openapi_*.ts" # OpenAPI
排除文档
ignore:
- docs/
- documentation/
- "*.md"
- "*.mdx"
- "*.rst"
验证忽略模式
检查正在建立索引的内容:
# Check index status
grepai status
# Output shows file count
# If too high, add more ignore patterns
常见问题
❌ 问题: 索引过大
✅ 解决方案: 添加更多忽略模式,以排除依赖项和生成的文件
❌ 问题: 搜索结果包含 vendor/测试代码
✅ 解决方案: 忽略这些文件,或使用加权惩罚
❌ 问题: 模式不起作用
✅ 解决方案: 检查语法;包含特殊字符的模式要使用引号:
ignore:
- "*.min.js" # Correct
- *.min.js # May cause YAML parsing issues
❌ 问题: 需要包含之前忽略的文件
✅ 解决方案: 从忽略列表中移除这些文件,然后重新运行 grepai watch
最佳实践
- 从默认设置开始: 按需添加模式
- 排除依赖项: 始终忽略
node_modules、vendor等 - 排除构建产物:
dist、build、target - 排除锁定文件: 这类文件很大,对搜索没有帮助
- 考虑加权而非忽略: 对测试文件施加惩罚,而不是排除
- 为特殊字符加引号: 使用
"*.min.js",而非*.min.js
更改后重新建立索引
修改忽略模式后:
# Stop existing daemon
grepai watch --stop
# Clear index and restart
rm .grepai/index.gob
grepai watch
输出格式
配置忽略模式后:
✅ Ignore Patterns Configured
Patterns: 15 configured
Categories:
- Directories: node_modules, vendor, dist, build
- File types: *.min.js, *.map, *.lock
- Paths: /tests/, /docs/
Also respecting: .gitignore
Run 'grepai watch' to re-index with new patterns.
评论
支持 Markdown