feat(core): add AGENTS.md to default context filenames#24913
feat(core): add AGENTS.md to default context filenames#24913harshpujari wants to merge 5 commits intogoogle-gemini:mainfrom
Conversation
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
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 enhances the Gemini CLI's ability to automatically discover AI agent instructions by integrating the 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
This pull request updates the Gemini CLI to discover both GEMINI.md and AGENTS.md files as context sources by default. The changes include documentation updates, modifications to the core configuration and prompt rendering logic, and expanded test coverage. Key feedback highlights a potential concurrency issue due to the use of module-level global state for filename configuration and a bug where an empty array of context filenames could result in 'undefined' being rendered in the system prompt.
| let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAME; | ||
| // This variable will hold the currently configured filenames for context files. | ||
| // It defaults to DEFAULT_CONTEXT_FILENAMES but can be overridden by setGeminiMdFilename. | ||
| let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAMES; |
There was a problem hiding this comment.
The use of a module-level global variable currentGeminiMdFilename for state violates the general rule against global state in concurrent environments. This can lead to race conditions in the a2a-server or when using the SDK, where multiple sessions might attempt to configure different context filenames simultaneously. Consider moving this state into a session-scoped object like the Config instance and passing it to the tools and prompt renderers.
References
- Avoid module-level global variables for state like caches to prevent race conditions and memory issues in concurrent environments. Instead, use session-scoped or instance-scoped state and leverage standard cache implementations like LRUCache.
| export function renderCoreMandates(options?: CoreMandatesOptions): string { | ||
| if (!options) return ''; | ||
| const filenames = options.contextFilenames ?? [DEFAULT_CONTEXT_FILENAME]; | ||
| const filenames = options.contextFilenames ?? DEFAULT_CONTEXT_FILENAMES; |
There was a problem hiding this comment.
If options.contextFilenames is an empty array, the current logic will result in filenames[0] being undefined on line 186, which will be rendered as the string 'undefined' in the system prompt. The fallback should ensure a non-empty array is used.
const filenames = options.contextFilenames?.length
? options.contextFilenames
: DEFAULT_CONTEXT_FILENAMES;References
- To avoid extra newlines or malformed content from empty variables in template literals, prefer ensuring the variable is never empty over adding conditional rendering logic within the template.
Prevents 'undefined' from being rendered in the system prompt when contextFilenames is an empty array, since [] is truthy and bypasses the ?? fallback.
e32317d to
e1f2352
Compare
|
The module-level currentGeminiMdFilename state is pre-existing — this PR doesn't introduce it. Refactoring it into session-scoped config (e.g., the Config instance) would be a valuable follow-up but is beyond the scope of this change. Happy to open a separate issue for it. |
Summary
AGENTS.mdalongsideGEMINI.mdas a default context file that is automatically discoveredcontext.fileNamein.gemini/settings.jsonto excludeAGENTS.mdif neededDetails
Codebases increasingly use the AGENTS.md standard for AI agent instructions. This change adds
AGENTS.mdto the default context filename list so it is discovered automatically without requiring manual configuration.The existing infrastructure already supports multiple filenames — this change simply adds
AGENTS.mdto the default list.GEMINI.mdremains the primary context file (first in the array).Changes
packages/core/src/tools/memoryTool.ts— AddedDEFAULT_CONTEXT_FILENAMESarray constant, updated default initializerpackages/core/src/prompts/snippets.ts— Updated fallback references to use new array constantdocs/cli/gemini-md.md— Documented AGENTS.md default discovery and override mechanismTest plan
context.fileNameconfigFixes #12345
🤖 Generated with Claude Code