fix(goose): load .gitignore in prompt_manager for hint file filtering#7795
fix(goose): load .gitignore in prompt_manager for hint file filtering#7795
Conversation
The GitignoreBuilder in prompt_manager.with_hints() was created but never loaded the actual .gitignore file via .add(), resulting in empty ignore patterns. This meant @-referenced files in .goosehints that should have been filtered by .gitignore were being expanded anyway. Now properly loads the working directory's .gitignore before building the ignore patterns passed to load_hint_files/read_referenced_files.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adbb3e0713
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut builder = ignore::gitignore::GitignoreBuilder::new(working_dir); | ||
| let gitignore_path = working_dir.join(".gitignore"); | ||
| if gitignore_path.is_file() { |
There was a problem hiding this comment.
Load .gitignore from repository root
with_hints now only loads working_dir/.gitignore, but load_hint_files resolves hint files from the git root down to the current directory. When users run Goose from a subdirectory (a common case), the repo-root .gitignore is skipped, so root-level ignored files referenced via @... in hints can still be expanded. This leaves the new filtering behavior inconsistent and can still expose ignored content outside the cwd-specific .gitignore case.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db6d10bf40
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let git_root = find_git_root(cwd); | ||
| let directories = get_local_directories(git_root, cwd); | ||
|
|
||
| let mut builder = GitignoreBuilder::new(cwd); |
There was a problem hiding this comment.
Build gitignore matcher relative to git root
build_gitignore adds .gitignore files from the repository root down to cwd, but the matcher is rooted at cwd (GitignoreBuilder::new(cwd)). In the ignore crate, patterns are evaluated relative to the builder root, so parent .gitignore entries like /secret.env or docs/*.md are misinterpreted when Goose runs from a subdirectory and can fail to filter @../... references that should be ignored. This means ignored files can still be expanded from hints in common subdirectory workflows; initialize the builder at git_root.unwrap_or(cwd) (or equivalent per-directory scoping) to preserve parent .gitignore semantics.
Useful? React with 👍 / 👎.
* main: (270 commits) test(acp): align provider and server test parity (#7822) fix(acp): register MCP extensions when resuming a session (#7806) fix(goose): load .gitignore in prompt_manager for hint file filtering (#7795) fix: remap max_completion_tokens to max_tokens for OpenAI-compatible providers (#7765) fix(openai): preserve Responses API tool call/output linkage (#7759) chore(deps): bump @hono/node-server from 1.19.9 to 1.19.11 in /evals/open-model-gym/mcp-harness (#7687) fix: return ContextLengthExceeded when prompt exceeds effective KV cache size (#7815) feat: MCP Roots support (#7790) fix(google): use `includeThoughts/part.thought` for thinking handling (#7593) refactor: simplify tokenizer initialization — remove unnecessary Result wrapper (#7744) Fix model selector showing wrong model in tabs (#7784) Stop collecting goosed stderr after startup (#7814) fix: avoid word splitting by space for windows shell commands (#7781) (#7810) Simplify and make it not break on linux (#7813) Add preferred microphone selection (#7805) Remove dependency on posthog-rs (#7811) feat: load hints in nested subdirs (#7772) feat(acp): add read tool and delegate filesystem I/O to ACP clients (#7668) Support secret interpolation in streamable HTTP extension URLs (#7782) More logging for command injection classifier model training (#7779) ...
Summary
The
GitignoreBuilderinprompt_manager.with_hints()was created but never loaded the actual.gitignorefile via.add(), resulting in empty ignore patterns. This meant@-referenced files in.goosehintsthat should have been filtered by.gitignorewere being expanded anyway.Changes
crates/goose/src/agents/prompt_manager.rs: Load the working directory's.gitignorefile into theGitignoreBuilderbefore building the ignore patterns passed toload_hint_files/read_referenced_files.crates/goose/src/hints/load_hints.rs: Added a test verifying that.gitignore-listed files referenced via@in hint files are not expanded.Context
Spotted during review of #7054 — the summarize extension's
build_gitignore()correctly loads.gitignore, but the prompt manager had the same builder pattern without the.add()call.Test Plan
test_hints_with_gitignore_filters_referenced_filesvalidates the fixcargo clippyclean