Skip to content

fix(goose): load .gitignore in prompt_manager for hint file filtering#7795

Merged
DOsinga merged 3 commits intomainfrom
fix/prompt-manager-gitignore
Mar 11, 2026
Merged

fix(goose): load .gitignore in prompt_manager for hint file filtering#7795
DOsinga merged 3 commits intomainfrom
fix/prompt-manager-gitignore

Conversation

@DOsinga
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga commented Mar 10, 2026

Summary

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.

Changes

  • crates/goose/src/agents/prompt_manager.rs: Load the working directory's .gitignore file into the GitignoreBuilder before building the ignore patterns passed to load_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

  • All existing hint/import tests pass
  • New test test_hints_with_gitignore_filters_referenced_files validates the fix
  • cargo clippy clean

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.
@DOsinga DOsinga requested a review from jamadeo March 10, 2026 21:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +101 to +103
let mut builder = ignore::gitignore::GitignoreBuilder::new(working_dir);
let gitignore_path = working_dir.join(".gitignore");
if gitignore_path.is_file() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@DOsinga DOsinga requested a review from alexhancock March 11, 2026 01:37
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@DOsinga DOsinga added this pull request to the merge queue Mar 11, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 11, 2026
@DOsinga DOsinga added this pull request to the merge queue Mar 11, 2026
Merged via the queue into main with commit 4578697 Mar 11, 2026
21 of 22 checks passed
@DOsinga DOsinga deleted the fix/prompt-manager-gitignore branch March 11, 2026 20:41
lifeizhou-ap added a commit that referenced this pull request Mar 12, 2026
* 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)
  ...
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