grepai-ignore-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI Ignore Patterns

GrepAI 忽略模式

This skill covers how to configure ignore patterns to exclude files and directories from GrepAI indexing.
本技能介绍如何配置忽略模式,以从GrepAI索引中排除文件和目录。

When to Use This Skill

何时使用此技能

  • Excluding test files from search results
  • Ignoring generated or vendored code
  • Reducing index size by excluding unnecessary files
  • Customizing which files GrepAI indexes
  • 从搜索结果中排除测试文件
  • 忽略生成的代码或第三方依赖代码
  • 通过排除不必要的文件来减小索引大小
  • 自定义GrepAI索引的文件范围

How Ignore Patterns Work

忽略模式的工作原理

GrepAI uses two sources for ignore patterns:
  1. .grepai/config.yaml
    - Custom patterns you define
  2. .gitignore
    - Automatically respected
GrepAI从两个来源获取忽略模式:
  1. .grepai/config.yaml
    - 你定义的自定义模式
  2. .gitignore
    - 会自动被识别

Configuration Location

配置位置

yaml
undefined
yaml
undefined

.grepai/config.yaml

.grepai/config.yaml

ignore:
  • pattern1
  • pattern2
undefined
ignore:
  • pattern1
  • pattern2
undefined

Pattern Syntax

模式语法

Directory Patterns

目录模式

yaml
ignore:
  # Exact directory name (matches anywhere)
  - node_modules
  - vendor
  - __pycache__

  # With trailing slash (explicit directory)
  - dist/
  - build/
  - coverage/
yaml
ignore:
  # 精确目录名称(可在任意位置匹配)
  - node_modules
  - vendor
  - __pycache__

  # 带末尾斜杠(明确指定为目录)
  - dist/
  - build/
  - coverage/

File Patterns

文件模式

yaml
ignore:
  # Exact filename
  - package-lock.json
  - yarn.lock

  # Wildcard patterns
  - "*.min.js"
  - "*.min.css"
  - "*.map"
  - "*.lock"
yaml
ignore:
  # 精确文件名
  - package-lock.json
  - yarn.lock

  # 通配符模式
  - "*.min.js"
  - "*.min.css"
  - "*.map"
  - "*.lock"

Path Patterns

路径模式

yaml
ignore:
  # Paths containing substring
  - /tests/
  - /spec/
  - /__tests__/

  # Specific paths
  - src/generated/
  - api/swagger/
yaml
ignore:
  # 包含指定子串的路径
  - /tests/
  - /spec/
  - /__tests__/

  # 特定路径
  - src/generated/
  - api/swagger/

Glob Patterns

全局模式(Glob Patterns)

yaml
ignore:
  # Double star (recursive)
  - "**/test/**"
  - "**/mock/**"

  # Single star (single level)
  - "*.test.js"
  - "*.spec.ts"
  - "*_test.go"
yaml
ignore:
  # 双星号(递归匹配)
  - "**/test/**"
  - "**/mock/**"

  # 单星号(单层级匹配)
  - "*.test.js"
  - "*.spec.ts"
  - "*_test.go"

Default Ignore Patterns

默认忽略模式

GrepAI's default configuration includes:
yaml
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
GrepAI的默认配置包含:
yaml
ignore:
  # 版本控制相关
  - .git
  - .svn
  - .hg

  # GrepAI自身文件
  - .grepai

  # 包管理器相关
  - node_modules
  - vendor
  - .npm
  - .yarn

  # 构建输出
  - target
  - dist
  - build
  - out

  # 缓存目录
  - __pycache__
  - .pytest_cache
  - .mypy_cache
  - .cache

  # 框架输出
  - .next
  - .nuxt
  - .output

Common Ignore Configurations

常见忽略配置

JavaScript/TypeScript Project

JavaScript/TypeScript 项目

yaml
ignore:
  - node_modules
  - dist
  - build
  - coverage
  - .nyc_output
  - "*.min.js"
  - "*.bundle.js"
  - "*.map"
  - package-lock.json
  - yarn.lock
  - pnpm-lock.yaml
yaml
ignore:
  - node_modules
  - dist
  - build
  - coverage
  - .nyc_output
  - "*.min.js"
  - "*.bundle.js"
  - "*.map"
  - package-lock.json
  - yarn.lock
  - pnpm-lock.yaml

Go Project

Go 项目

yaml
ignore:
  - vendor
  - bin
  - "*.pb.go"       # Protobuf generated
  - "*_mock.go"     # Mocks
  - "mocks/"
  - go.sum
yaml
ignore:
  - vendor
  - bin
  - "*.pb.go"       # Protobuf 生成文件
  - "*_mock.go"     # 模拟文件
  - "mocks/"
  - go.sum

Python Project

Python 项目

yaml
ignore:
  - __pycache__
  - .pytest_cache
  - .mypy_cache
  - .venv
  - venv
  - env
  - "*.pyc"
  - "*.pyo"
  - .eggs
  - "*.egg-info"
  - dist
  - build
yaml
ignore:
  - __pycache__
  - .pytest_cache
  - .mypy_cache
  - .venv
  - venv
  - env
  - "*.pyc"
  - "*.pyo"
  - .eggs
  - "*.egg-info"
  - dist
  - build

Rust Project

Rust 项目

yaml
ignore:
  - target
  - Cargo.lock
  - "*.rlib"
yaml
ignore:
  - target
  - Cargo.lock
  - "*.rlib"

Java/Kotlin Project

Java/Kotlin 项目

yaml
ignore:
  - target
  - build
  - .gradle
  - "*.class"
  - "*.jar"
  - "*.war"
yaml
ignore:
  - target
  - build
  - .gradle
  - "*.class"
  - "*.jar"
  - "*.war"

Monorepo

单体仓库(Monorepo)

yaml
ignore:
  # Common
  - node_modules
  - dist
  - build
  - coverage

  # Specific packages to exclude
  - packages/legacy/
  - packages/deprecated/

  # Generated
  - "**/generated/**"
  - "**/__generated__/**"
yaml
ignore:
  # 通用忽略项
  - node_modules
  - dist
  - build
  - coverage

  # 要排除的特定包
  - packages/legacy/
  - packages/deprecated/

  # 生成的文件
  - "**/generated/**"
  - "**/__generated__/**"

Excluding Test Files

排除测试文件

To focus search on production code:
yaml
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"
Alternative: Use search boosting instead to penalize (not exclude) tests:
yaml
search:
  boost:
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
若要将搜索重点放在生产代码上:
yaml
ignore:
  # 测试目录
  - tests/
  - test/
  - __tests__/
  - spec/

  # 按模式匹配测试文件
  - "*.test.js"
  - "*.test.ts"
  - "*.spec.js"
  - "*.spec.ts"
  - "*_test.go"
  - "test_*.py"
  - "*_test.py"
替代方案: 使用搜索权重调整来降低(而非排除)测试文件的优先级:
yaml
search:
  boost:
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5

Excluding Generated Code

排除生成的代码

yaml
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
yaml
ignore:
  # 生成文件标记
  - "**/generated/**"
  - "*.generated.*"
  - "*.gen.*"

  # 特定生成器的输出
  - "*.pb.go"           # Protobuf
  - "*.graphql.ts"      # GraphQL 代码生成
  - "*.d.ts"            # TypeScript 声明文件
  - "swagger_*.go"      # Swagger
  - "openapi_*.ts"      # OpenAPI

Excluding Documentation

排除文档

yaml
ignore:
  - docs/
  - documentation/
  - "*.md"
  - "*.mdx"
  - "*.rst"
yaml
ignore:
  - docs/
  - documentation/
  - "*.md"
  - "*.mdx"
  - "*.rst"

Verifying Ignore Patterns

验证忽略模式

Check what's being indexed:
bash
undefined
检查当前索引的内容:
bash
undefined

Check index status

检查索引状态

grepai status
grepai status

Output shows file count

输出会显示文件数量

If too high, add more ignore patterns

如果数量过多,添加更多忽略模式

undefined
undefined

Common Issues

常见问题

Problem: Index is too large ✅ Solution: Add more ignore patterns for dependencies and generated files
Problem: Search returns vendor/test code ✅ Solution: Either ignore or use boosting penalties
Problem: Pattern not working ✅ Solution: Check syntax - use quotes for patterns with special characters:
yaml
ignore:
  - "*.min.js"  # Correct
  - *.min.js    # May cause YAML parsing issues
Problem: Need to include previously ignored files ✅ Solution: Remove from ignore list and re-run
grepai watch
问题: 索引体积过大 ✅ 解决方案: 为依赖文件和生成文件添加更多忽略模式
问题: 搜索结果包含第三方依赖/测试代码 ✅ 解决方案: 要么忽略这些文件,要么使用权重调整降低其优先级
问题: 模式不生效 ✅ 解决方案: 检查语法 - 对包含特殊字符的模式使用引号:
yaml
ignore:
  - "*.min.js"  # 正确写法
  - *.min.js    # 可能会导致YAML解析问题
问题: 需要重新包含之前被忽略的文件 ✅ 解决方案: 从忽略列表中移除该模式,然后重新运行
grepai watch

Best Practices

最佳实践

  1. Start with defaults: Add patterns as needed
  2. Exclude dependencies: Always ignore
    node_modules
    ,
    vendor
    , etc.
  3. Exclude build outputs:
    dist
    ,
    build
    ,
    target
  4. Exclude lock files: Large, not useful for search
  5. Consider boosting vs ignoring: Penalize instead of exclude for test files
  6. Quote special characters:
    "*.min.js"
    not
    *.min.js
  1. 从默认配置开始: 根据需要添加自定义模式
  2. 排除依赖文件: 始终忽略
    node_modules
    vendor
    等目录
  3. 排除构建输出:
    dist
    build
    target
  4. 排除锁文件: 这类文件体积大,对搜索无帮助
  5. 考虑权重调整 vs 忽略: 对测试文件优先使用权重降低而非直接忽略
  6. 为特殊字符添加引号: 使用
    "*.min.js"
    而非
    *.min.js

Re-indexing After Changes

修改后重新索引

After modifying ignore patterns:
bash
undefined
修改忽略模式后:
bash
undefined

Stop existing daemon

停止现有守护进程

grepai watch --stop
grepai watch --stop

Clear index and restart

清除索引并重启

rm .grepai/index.gob grepai watch
undefined
rm .grepai/index.gob grepai watch
undefined

Output Format

输出格式

After configuring ignore patterns:
✅ 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.
配置忽略模式后:
✅ 忽略模式已配置

   模式数量:已配置15个

   分类:
   - 目录:node_modules, vendor, dist, build
   - 文件类型:*.min.js, *.map, *.lock
   - 路径:/tests/, /docs/

   同时会遵循:.gitignore

   运行 'grepai watch' 以使用新模式重新索引。