Skip to content

fix(core): made context files append instead of replace#26950

Open
devr0306 wants to merge 8 commits into
mainfrom
context-file-name
Open

fix(core): made context files append instead of replace#26950
devr0306 wants to merge 8 commits into
mainfrom
context-file-name

Conversation

@devr0306
Copy link
Copy Markdown
Contributor

@devr0306 devr0306 commented May 12, 2026

Summary

Made context files append instead of replace when settings.context.fileName is set.

Details

  • Context File Handling: Updated the context file configuration to support appending new filenames instead of replacing existing ones when using setGeminiMdFilename.
  • New Reset Functionality: Introduced a resetGeminiMdFilename function to allow for explicit replacement or resetting of the context file list to defaults.
  • Test Coverage: Expanded the test suite to verify appending behavior, uniqueness constraints, and the new reset functionality.

Related Issues

Fixes #26728

How to Validate

Add

"context": {
   "fileName": ["AGENTS.md"]
}

with a file AGENTS.md that could contain any text. Start Gemini CLI and run /memory show. It should include the context from AGENTS.md.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@devr0306 devr0306 requested a review from a team as a code owner May 12, 2026 21:18
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 modifies how context files are managed in the Gemini CLI, shifting from a replacement-based model to an additive one. By allowing multiple context files to be registered simultaneously, users can now include more diverse memory sources without overwriting previous configurations. The changes include robust handling for uniqueness and a new reset mechanism to maintain control over the configuration state.

Highlights

  • Context File Handling: Updated the context file configuration to support appending new filenames instead of replacing existing ones when using setGeminiMdFilename.
  • New Reset Functionality: Introduced a resetGeminiMdFilename function to allow for explicit replacement or resetting of the context file list to defaults.
  • Test Coverage: Expanded the test suite to verify appending behavior, uniqueness constraints, and the new reset functionality.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Size Change: +1.03 kB (0%)

Total Size: 34.1 MB

Filename Size Change
./bundle/chunk-7BNI4AA2.js 0 B -1.98 MB (removed) 🏆
./bundle/chunk-CVJA4NGW.js 0 B -2.79 MB (removed) 🏆
./bundle/chunk-DTYQGBIG.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-LS2TQJ35.js 0 B -3.8 kB (removed) 🏆
./bundle/chunk-OCY5N34Q.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-TPN6AQRQ.js 0 B -659 kB (removed) 🏆
./bundle/chunk-UWM6DCB5.js 0 B -14.8 MB (removed) 🏆
./bundle/chunk-YHFK23HJ.js 0 B -12.5 kB (removed) 🏆
./bundle/chunk-ZDASTAYR.js 0 B -19.5 kB (removed) 🏆
./bundle/core-T7OOWSQO.js 0 B -49.3 kB (removed) 🏆
./bundle/devtoolsService-WC4FSMQQ.js 0 B -28 kB (removed) 🏆
./bundle/gemini-3NCAN3KL.js 0 B -587 kB (removed) 🏆
./bundle/interactiveCli-RD2SJ4LZ.js 0 B -1.3 MB (removed) 🏆
./bundle/liteRtServerManager-QOEWEFPI.js 0 B -2.11 kB (removed) 🏆
./bundle/oauth2-provider-K4WBTHNC.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-2TXJHS6W.js 2.79 MB +2.79 MB (new file) 🆕
./bundle/chunk-33WBEAIU.js 12.5 kB +12.5 kB (new file) 🆕
./bundle/chunk-4ICEOCUP.js 14.8 MB +14.8 MB (new file) 🆕
./bundle/chunk-4YHUUXAM.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-5GYMQDFY.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-62Q4AIBF.js 659 kB +659 kB (new file) 🆕
./bundle/chunk-DMQDOOWS.js 1.98 MB +1.98 MB (new file) 🆕
./bundle/chunk-J4KHXFYY.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-WECIQEQZ.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/core-TXN4LTV3.js 49.4 kB +49.4 kB (new file) 🆕
./bundle/devtoolsService-BUKQYPR7.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-VTM74S6X.js 587 kB +587 kB (new file) 🆕
./bundle/interactiveCli-GTOZQTKP.js 1.3 MB +1.3 MB (new file) 🆕
./bundle/liteRtServerManager-YEOUOQGK.js 2.11 kB +2.11 kB (new file) 🆕
./bundle/oauth2-provider-IC5AHXLN.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-PEUPB5A6.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.1 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-URNH4AK4.js 0 B -980 B (removed) 🏆
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/start-TWOLEIBW.js 0 B -652 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-FMQ3PUWS.js 932 B +932 B (new file) 🆕
./bundle/memoryDiscovery-KB3UQ2VI.js 980 B +980 B (new file) 🆕
./bundle/start-FLVUYD2T.js 652 B +652 B (new file) 🆕

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the memory tool to support multiple context filenames by modifying setGeminiMdFilename to append new names and introducing a resetGeminiMdFilename function. Feedback identifies critical path traversal vulnerabilities in both functions due to a lack of input sanitization. Additionally, the reviewer suggested a logic improvement for setGeminiMdFilename to ensure that newly added filenames take precedence over existing ones.

Comment thread packages/core/src/tools/memoryTool.ts
Comment thread packages/core/src/tools/memoryTool.ts
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 modifies the memory tool configuration to support appending multiple context files rather than overwriting the previous configuration. This change improves flexibility for users who need to include multiple context sources simultaneously. A new reset function has been introduced to manage the state explicitly, ensuring backward compatibility and cleaner configuration management.

Highlights

  • Context File Handling: Updated the context file management logic to append new filenames instead of replacing existing ones when setting context files.
  • New Utility Function: Introduced resetGeminiMdFilename to allow explicit replacement or resetting of the context file list to the default.
  • Test Coverage: Added comprehensive unit tests to verify the new appending behavior, uniqueness constraints, and reset functionality.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the memory tool to support multiple context filenames, modifying setGeminiMdFilename to append unique names and introducing resetGeminiMdFilename to manage the list. Feedback identifies critical path traversal vulnerabilities in both functions, suggesting the need for path normalization and sanitization. Additionally, the reviewer recommends refactoring the module-level global state to instance-scoped properties to avoid potential race conditions in concurrent environments.

Comment thread packages/core/src/tools/memoryTool.ts
Comment thread packages/core/src/tools/memoryTool.ts
Comment thread packages/core/src/tools/memoryTool.ts
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 refactors the mechanism for managing context files within the application. Previously, setting a new context filename would overwrite any existing configuration. The updated logic now allows for context files to be appended, enabling the use of multiple context files concurrently. A dedicated reset function has also been added to provide explicit control over clearing and re-establishing context file settings.

Highlights

  • Context File Handling: The setGeminiMdFilename function has been updated to append new context filenames instead of replacing the existing ones, allowing for multiple context files to be active simultaneously.
  • New Reset Functionality: A new function, resetGeminiMdFilename, was introduced to explicitly replace all current context filenames with a new set or reset them to the default.
  • Improved Test Coverage: Existing tests for setGeminiMdFilename were updated to reflect the new appending behavior, and new tests were added for the resetGeminiMdFilename function, including uniqueness checks.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the memoryTool to support multiple context filenames by modifying setGeminiMdFilename to append unique names and introducing a resetGeminiMdFilename function. Feedback highlights critical security vulnerabilities related to path traversal in both functions due to a lack of input sanitization. Additionally, the reviewer noted that using a module-level global variable for mutable state violates project guidelines for concurrent environments and recommended refactoring to instance-scoped state.

Comment thread packages/core/src/tools/memoryTool.ts
Comment thread packages/core/src/tools/memoryTool.ts
Comment thread packages/core/src/tools/memoryTool.ts
Fix path traversal for `resetGeminiMdFilename`

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels May 12, 2026
@gemini-cli gemini-cli Bot added the area/security Issues related to security label May 13, 2026
@devr0306 devr0306 changed the title fix(ui): made context files append instead of replace fix(core): made context files append instead of replace May 13, 2026
@devr0306 devr0306 requested a review from a team as a code owner May 13, 2026 15:38
@cocosheng-g
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the MemoryTool to support multiple context filenames by modifying setGeminiMdFilename to append unique, sanitized filenames and introducing resetGeminiMdFilename for replacing the filename list. The CLI configuration and associated tests were updated to reflect these changes. Feedback highlights potential path traversal vulnerabilities on Windows within the manual sanitization logic, recommending the use of a centralized resolveToRealPath utility for more robust validation. Additionally, an import update was suggested in the CLI configuration to support idempotent loading logic.

Comment thread packages/core/src/tools/memoryTool.ts Outdated
Comment thread packages/core/src/tools/memoryTool.ts Outdated
Comment thread packages/cli/src/config/config.ts
Copy link
Copy Markdown
Contributor

@cocosheng-g cocosheng-g left a comment

Choose a reason for hiding this comment

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

please address bot comments otherwise lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality area/core Issues related to User Interface, OS Support, Core Functionality area/security Issues related to security priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contextFileName in settings.json does not work.

2 participants