feat(core): cap JIT context upward traversal at git root#23074
feat(core): cap JIT context upward traversal at git root#23074SandyTao520 merged 1 commit intomainfrom
Conversation
|
Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines how JIT context memory is discovered by aligning the upward traversal boundary with the project's git root. Previously, traversal was limited by a "trusted root," which could lead to either overly narrow or broad context discovery. By using the git root as the ceiling, and skipping traversal altogether if no git root is present, the system now more intelligently identifies relevant Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements the feature to cap JIT context upward traversal at the git root. The changes in memoryDiscovery.ts correctly modify getEnvironmentMemoryPaths and loadJitSubdirectoryMemory to use the findProjectRoot() function and limit traversal to the detected git repository root. If no git root is found, the upward traversal is appropriately skipped. The accompanying test updates in memoryDiscovery.test.ts accurately reflect this new behavior, ensuring the functionality works as intended. The debug logging has also been updated to provide clearer information about the traversal boundaries. The implementation is clean and directly addresses the problem described in the PR description.
|
Size Change: +340 B (0%) Total Size: 26.2 MB
ℹ️ View Unchanged
|
11cf03f to
1dae438
Compare
Previously, JIT context (getEnvironmentMemoryPaths and loadJitSubdirectoryMemory) used the trusted root as the traversal ceiling, which could be too narrow. Change both functions to find the git project root via findProjectRoot and use it as the ceiling instead. If no git root exists, skip upward traversal entirely to avoid walking into unrelated parent directories.
1dae438 to
c5594c1
Compare
|
/patch preview |
|
🚀 [Step 1/4] Patch workflow(s) waiting for approval! 📋 Details:
⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs. 🔗 Track Progress: |
|
🚀 [Step 2/4] Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 [Step 3/4] Patch Release Waiting for Approval! 📋 Release Details:
⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ [Step 4/4] Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
Summary
Cap JIT context upward traversal at the git root instead of the trusted root. Also fix
findProjectRootto recognize.gitfiles (submodules/worktrees), not just.gitdirectories.Details
Both
getEnvironmentMemoryPaths(Tier 2) andloadJitSubdirectoryMemory(Tier 3) previously used the trusted root as the traversal ceiling for GEMINI.md discovery. This was too narrow — Tier 2 only checked the workspace root directory itself (sincestartDir === stopDir), and Tier 3 stopped at the deepest trusted root.Changes:
Git root as ceiling: Both functions now call
findProjectRoot()to locate.gitand use that as the traversal ceiling. This prevents walking into unrelated parent directories while still picking up GEMINI.md files between the trusted root and the git root.No-git fallback: When no git root is found (e.g., a quick script folder), the trusted root is used as the ceiling — preserving the old behavior so GEMINI.md files at the trusted root itself are still loaded.
Submodule/worktree support:
findProjectRootnow usesfs.access()instead offs.lstat() + isDirectory(), so.gitfiles (used by submodules and worktrees) are recognized as project roots. This was a pre-existing gap that affected all callers offindProjectRoot, including the non-JIT path.Related Issues
Related to #18007
How to Validate
npm test -w @google/gemini-cli-core -- src/utils/memoryDiscovery.test.ts— all 39 tests pass.getEnvironmentMemoryPaths→ "should traverse upward from trusted root to git root" — traversal reaches the git root but not beyond.getEnvironmentMemoryPaths→ "should fall back to trusted root as ceiling when no .git exists" — non-git dirs still load their own GEMINI.md.getEnvironmentMemoryPaths→ "should recognize .git as a file (submodules/worktrees)" —.gitfile is treated as a project root.loadJitSubdirectoryMemory→ "should fall back to trusted root as ceiling when no git root exists" — JIT still works in non-git dirs.loadJitSubdirectoryMemory→ "should use the deepest trusted root when multiple nested roots exist" — traversal reaches git root from the deepest trusted root.Pre-Merge Checklist