Skip to content

feat: Read .gooseignore to Restrict access to files or Directories#1199

Merged
ZhenLian merged 3 commits intomainfrom
zhen_file_acl_1
Feb 27, 2025
Merged

feat: Read .gooseignore to Restrict access to files or Directories#1199
ZhenLian merged 3 commits intomainfrom
zhen_file_acl_1

Conversation

@ZhenLian
Copy link
Copy Markdown
Contributor

@ZhenLian ZhenLian commented Feb 12, 2025

Description

This aims to implement the feature described in issue #1065, enabling Goose's developer tool to read a .gooseignore file, which can be defined globally or locally (similar to how the .goosehints file is read). The tool will prevent text_editor or bash from opening any files or directories specified in .gooseignore. The naming conventions for .gooseignore align with those defined in Gitignore documentation.

testing

  • unit tests and tested with cargo test
  • tested on Goose CLI
    ------------------screenshots for the 3rd round of review
    goose can take case-insensitive scenarios into account:
    goose6

------------------screenshots for the second round of review
the bash tool ignoring feature still works as expected:
Screenshot 2025-02-25 at 9 41 13 PM

and if we remove all ignore files, things will behave normal:
Screenshot 2025-02-25 at 9 43 39 PM

------------------screenshots for initial commit

goose1
goose2
and here is my .gooseignore file used for testing:
Screenshot 2025-02-25 at 8 12 56 AM

@ZhenLian ZhenLian changed the title WIP: Add Abilities to read ignore files to Restrict access to files feat: Read .gooseignore to Restrict access to files or Directories Feb 25, 2025
@ZhenLian ZhenLian marked this pull request as ready for review February 25, 2025 16:15
}

// Only use default patterns if no .gooseignore files were found
// If the file is empty, we will not ignore any file
Copy link
Copy Markdown

@wendytang wendytang Feb 25, 2025

Choose a reason for hiding this comment

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

needs a check if the file is actually empty

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we had previously included two checks: if global_ignore_path.is_file() and if local_ignore_path.is_file(). If any of these files are empty, they won't be read. In the description section, I've added a screenshot of the program running without any ignore files, and it functions just as it did before.

// Helper method to check if a shell command might access ignored files
fn check_command_for_ignored_files(&self, command: &str) -> Option<String> {
// Common file reading/writing commands to check
let file_commands = ["cat", "less", "more", "head", "tail", "grep", "awk", "sed"];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm hesitant to include hard-coded commands

}

// If it's a known file-accessing command, check the arguments
if file_commands.contains(&cmd_parts[0]) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

would it be possible to change the implementation slightly: when a file is in is_ignored, just skip any bash call for it entirely

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that sounds like a much better solution, updated the code!

Copy link
Copy Markdown

@wendytang wendytang left a comment

Choose a reason for hiding this comment

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

Would it be possible to change the implementation slightly: when a file is in is_ignored, just skip any bash call for it entirely? That way, we don't have to include all the hardcoded bash commands

@ZhenLian
Copy link
Copy Markdown
Contributor Author

@wendytang Hey Wendy, thanks a lot for the review! I've updated the code - would you mind taking a look again? Thank you!

@ZhenLian ZhenLian requested a review from wendytang February 26, 2025 05:54

// Helper method to check if a path should be ignored
fn is_ignored(&self, path: &Path) -> bool {
self.ignore_patterns.matched(path, false).is_ignore()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: make sure to account for upper and lower case

for example:

README.md
readme.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see what you mean. The actual ignore logic is managed by the Gitignore crate, and users are responsible for defining the rules in their gooseignore file.

In this example, the rules might look like "**/[Re][Ee][Aa][Dd][Mm][Ee].md". You can find more about the rules here: https://www.atlassian.com/git/tutorials/saving-changes/gitignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a new screenshot in the description section to showcase that Goose can work in this scenario

@ZhenLian
Copy link
Copy Markdown
Contributor Author

@wendytang Hey Wendy, I am going to merge this, but if you spot anything that we need to address, feel free to let me know. I am happy to take a look! :)

@ZhenLian ZhenLian merged commit f73ba9f into main Feb 27, 2025
6 checks passed
@ZhenLian ZhenLian deleted the zhen_file_acl_1 branch February 27, 2025 16:27
salman1993 added a commit that referenced this pull request Feb 27, 2025
* origin/main: (26 commits)
  feat: Read .gooseignore to Restrict access to files or Directories (#1199)
  docs: adding update command to cli command guide (#1411)
  docs: Adding YT short for Computer Controller Tutorial (#1420)
  feat(cli): support arbitrary path for sessions (#1414)
  feat: remove the disable state from chat input box (#1341)
  feat: Add extra details to prompt for gui (#1387)
  style: added launch text and styling (#1406)
  fix(docs): update default session location (#1412)
  feat: moved extension add button and updated label (#1408)
  draft: use rust messages in typescript (#1393)
  fix: detect read only tool when only mode is approve (#1398)
  docs: Add Puppeteer Extension Tutorial (#1396)
  chore(release): release version v1.0.10 (#1404)
  chore(release): release 1.10.0  (#1385)
  feat: wip on ConfigProvider and integration in settings_v2 (#1395)
  feat: Add command `goose update` to update goose CLI version (#1308)
  fix: update approve prompt (#1383)
  feat: interactive after run (#1377)
  docs: Tutorial extension (#1379)
  feat: allow setting openai base path (#1369)
  ...
kalvinnchau added a commit that referenced this pull request Feb 27, 2025
* main:
  feat: allow user to turn off smart approve (#1407)
  feat: Read .gooseignore to Restrict access to files or Directories (#1199)
  docs: adding update command to cli command guide (#1411)
  docs: Adding YT short for Computer Controller Tutorial (#1420)
  feat(cli): support arbitrary path for sessions (#1414)
  feat: remove the disable state from chat input box (#1341)
  feat: Add extra details to prompt for gui (#1387)
  style: added launch text and styling (#1406)
  fix(docs): update default session location (#1412)
  feat: moved extension add button and updated label (#1408)
  draft: use rust messages in typescript (#1393)
  fix: detect read only tool when only mode is approve (#1398)
  docs: Add Puppeteer Extension Tutorial (#1396)
  chore(release): release version v1.0.10 (#1404)
  chore(release): release 1.10.0  (#1385)
  feat: wip on ConfigProvider and integration in settings_v2 (#1395)
  feat: Add command `goose update` to update goose CLI version (#1308)
cbruyndoncx pushed a commit to cbruyndoncx/goose that referenced this pull request Jul 20, 2025
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.

2 participants