Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .clineignore support #490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

HeavenOSK
Copy link

@HeavenOSK HeavenOSK commented Jan 22, 2025

Overview

This PR introduces support for .clineignore files, allowing users to specify which files should be ignored during Cline operations.

Changes

  • Implemented .clineignore file parsing and pattern matching
  • Added support for glob patterns and negation patterns
  • Integrated ignore patterns with existing file processing systems
  • Added comprehensive test coverage for ignore pattern functionality

Implementation Details

  • Added new utility functions for handling ignore patterns
  • Integrated with extract-text, list-files, and ripgrep services
  • Support for various pattern types:
    • Exact matches
    • Wildcards
    • Directory patterns
    • Negation patterns

Testing

Added comprehensive test suite covering:

  • Basic pattern matching
  • Wildcard patterns
  • Directory patterns
  • Negation patterns
  • Complex pattern combinations

Impact

This change improves user control over which files are processed by Cline, making the tool more efficient and customizable.

Scenarios

[Task] What is written in the .env file?
[Task] Search for the string SAMPLE_API_KEY and list the files.
.clineignore files are not listed in the Current Working Directory

- Implemented `loadClineIgnoreFile` to read and return contents of `.clineignore`.
- Created `shouldIgnorePath` function to determine if a file path should be ignored based on patterns in the ignore file.
- Added tests for `shouldIgnorePath` covering exact matches, wildcards, directory patterns, comments, and negation patterns.
- Introduced new files: `src/utils/cline-ignore.ts` and `src/utils/__tests__/cline-ignore.test.ts`.

Enhance cline-ignore utility with additional functions and documentation

- Added `parseIgnorePatterns` function to streamline parsing of .clineignore file.
- Implemented `loadIgnorePatterns` to load patterns and provide an evaluation function.
- Introduced `filterIgnoredPaths` for batch filtering of file paths based on ignore patterns.
- Improved documentation with JSDoc comments for better clarity on function usage.
Copy link

changeset-bot bot commented Jan 22, 2025

⚠️ No Changeset found

Latest commit: 38c0566

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

src/utils/cline-ignore.ts Show resolved Hide resolved
// Escape special characters
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
// Convert wildcard * to regex pattern
.replace(/\*/g, ".*")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding support for the '?' wildcard in glob patterns by replacing it with '.' in the regex.

@mrubens
Copy link
Collaborator

mrubens commented Jan 22, 2025

Amazing - I've been wanting this! Will take a close look later today.

Thanks so much for your contributions. We've come a long way since first pulling in the sounds PR 😁

@HeavenOSK
Copy link
Author

Thank you so much for checking it out! I recently revisited Roo-Code after a while and was really impressed with how much it has improved.

There’s one aspect of this Pull Request that I’m still on the fence about: I’ve been excluding any files that match .clineignore from the Current Working Directory listing. But I’m starting to think this might not be the best approach. Perhaps it would be better not to exclude them entirely, and instead leverage the .clineignore content directly within the systemPrompt.

Also, please feel free to modify my Pull Request however you see fit—I’m more than happy for you to make any changes you think are best.

@mrubens
Copy link
Collaborator

mrubens commented Jan 24, 2025

One thing I'm thinking about is that we should probably prevent writing to files in the .clineignore as well.

I have a somewhat related task on my plate to restrict which files tools can access (for instance architect should only be able to write *.md files, a tester role maybe should only be able to write *.test.ts files, etc). Let me think a bit about the best place to put that logic - the .clineignore check may fit nicely there as well.

@HeavenOSK
Copy link
Author

That's a great point! It definitely makes sense to prevent writing to the .clineignore file. Additionally, the idea that access can vary by role offers an interesting perspective on viewing development as an organic process.

@mrubens
Copy link
Collaborator

mrubens commented Jan 25, 2025

I think I’m getting close - will try to share something with you tonight my time!

@mrubens
Copy link
Collaborator

mrubens commented Jan 26, 2025

This is the approach I'm playing around with, but for some reason can't get the project to build. #572

@aosan
Copy link

aosan commented Jan 26, 2025

why not call the file .rooignore? 🦘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants