Skip to content

feat: Add .gitignore awareness for file operations #107

Description

@CarGDev

Summary

Respect .gitignore patterns when listing files, loading context, and showing file picker.

Why It's Needed

  • Context Quality: Don't waste tokens on node_modules, build artifacts
  • File Picker UX: Don't show irrelevant files in @ picker
  • Search Quality: Grep/glob results exclude ignored files
  • Performance: Skip large ignored directories

Current Problem

@ file picker shows:
├── node_modules/           # 50,000+ files
├── dist/                   # Build artifacts
├── .git/                   # Git internals
├── coverage/               # Test coverage
└── src/                    # Actual source

Proposed Behavior

@ file picker shows:
└── src/                    # Only relevant files
    ├── index.ts
    ├── services/
    └── utils/

Implementation

import ignore from "ignore"

async function loadIgnorePatterns(cwd: string): Promise<Ignore> {
  const ig = ignore()
  
  // Load .gitignore
  const gitignore = await readFile(path.join(cwd, ".gitignore"), "utf-8").catch(() => "")
  ig.add(gitignore)
  
  // Load .codetyperignore (custom ignore)
  const codetyperignore = await readFile(path.join(cwd, ".codetyperignore"), "utf-8").catch(() => "")
  ig.add(codetyperignore)
  
  // Always ignore these
  ig.add([
    "node_modules",
    ".git",
    "dist",
    "build",
    "coverage",
    ".codetyper-backup",
  ])
  
  return ig
}

function filterFiles(files: string[], ig: Ignore): string[] {
  return files.filter(f => !ig.ignores(f))
}

Apply To

  • File picker (@ mentions)
  • Glob tool results
  • Grep tool results
  • Context file loading
  • Directory listings

Configuration

{
  "ignore": {
    "useGitignore": true,
    "useCodyterignore": true,
    "additional": ["*.log", "tmp/"]
  }
}

Acceptance Criteria

  • Parse and respect .gitignore
  • Support .codetyperignore for custom patterns
  • Filter file picker results
  • Filter glob results
  • Filter grep results
  • Always ignore node_modules, .git, dist, build
  • Configurable additional ignore patterns

Effort Estimate

0.5 days

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority-criticalCritical priority - implement first

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions