This commit is contained in:
Harsh Pujari 2026-04-21 04:31:48 +00:00 committed by GitHub
commit 1a825d50b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 12 deletions

View file

@ -91,18 +91,36 @@ More content here.
For more details, see the [Memory Import Processor](../reference/memport.md)
documentation.
## Default context file names
By default, Gemini CLI discovers both `GEMINI.md` and `AGENTS.md` files as
context sources. This means if your codebase uses the
[AGENTS.md](https://agents.md) standard, those instructions will be
automatically loaded alongside any `GEMINI.md` files.
## Customize the context file name
While `GEMINI.md` is the default filename, you can configure this in your
`settings.json` file. To specify a different name or a list of names, use the
`context.fileName` property.
You can configure which context filenames are discovered in your `settings.json`
file. To specify a different name or a list of names, use the `context.fileName`
property. This overrides the defaults, so you can use it to remove `AGENTS.md`
from discovery if it causes problems.
**Example `settings.json`:**
```json
{
"context": {
"fileName": ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]
"fileName": ["GEMINI.md"]
}
}
```
To add additional custom context files alongside the defaults:
```json
{
"context": {
"fileName": ["GEMINI.md", "AGENTS.md", "CONTEXT.md"]
}
}
```

View file

@ -129,6 +129,7 @@ vi.mock('../tools/memoryTool', () => ({
setGeminiMdFilename: vi.fn(),
getCurrentGeminiMdFilename: vi.fn(() => 'GEMINI.md'), // Mock the original filename
DEFAULT_CONTEXT_FILENAME: 'GEMINI.md',
DEFAULT_CONTEXT_FILENAMES: ['GEMINI.md', 'AGENTS.md'],
GEMINI_DIR: '.gemini',
}));

View file

@ -177,7 +177,9 @@ export function renderPreamble(options?: PreambleOptions): string {
export function renderCoreMandates(options?: CoreMandatesOptions): string {
if (!options) return '';
const filenames = options.contextFilenames ?? [DEFAULT_CONTEXT_FILENAME];
const filenames = options.contextFilenames?.length
? options.contextFilenames
: [DEFAULT_CONTEXT_FILENAME];
const formattedFilenames =
filenames.length > 1
? filenames
@ -497,7 +499,9 @@ export function renderUserMemory(
if (typeof memory === 'string') {
const trimmed = memory.trim();
if (trimmed.length === 0) return '';
const filenames = contextFilenames ?? [DEFAULT_CONTEXT_FILENAME];
const filenames = contextFilenames?.length
? contextFilenames
: [DEFAULT_CONTEXT_FILENAME];
const formattedHeader = filenames.join(', ');
return `
# Contextual Instructions (${formattedHeader})

View file

@ -18,7 +18,7 @@ import {
setGeminiMdFilename,
getCurrentGeminiMdFilename,
getAllGeminiMdFilenames,
DEFAULT_CONTEXT_FILENAME,
DEFAULT_CONTEXT_FILENAMES,
getProjectMemoryFilePath,
} from './memoryTool.js';
import type { Storage } from '../config/storage.js';
@ -76,7 +76,7 @@ describe('MemoryTool', () => {
afterEach(() => {
vi.restoreAllMocks();
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAME);
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAMES);
});
describe('setGeminiMdFilename', () => {
@ -101,6 +101,17 @@ describe('MemoryTool', () => {
expect(getCurrentGeminiMdFilename()).toBe('CUSTOM_CONTEXT.md');
expect(getAllGeminiMdFilenames()).toEqual(newNames);
});
it('should include AGENTS.md in default filenames', () => {
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAMES);
expect(getAllGeminiMdFilenames()).toEqual(['GEMINI.md', 'AGENTS.md']);
expect(getCurrentGeminiMdFilename()).toBe('GEMINI.md');
});
it('should allow overriding defaults to exclude AGENTS.md', () => {
setGeminiMdFilename('GEMINI.md');
expect(getAllGeminiMdFilenames()).toEqual(['GEMINI.md']);
});
});
describe('execute (instance method)', () => {

View file

@ -30,11 +30,12 @@ import { MEMORY_DEFINITION } from './definitions/coreTools.js';
import { resolveToolDeclaration } from './definitions/resolver.js';
export const DEFAULT_CONTEXT_FILENAME = 'GEMINI.md';
export const DEFAULT_CONTEXT_FILENAMES = ['GEMINI.md', 'AGENTS.md'];
export const MEMORY_SECTION_HEADER = '## Gemini Added Memories';
// This variable will hold the currently configured filename for GEMINI.md context files.
// It defaults to DEFAULT_CONTEXT_FILENAME but can be overridden by setGeminiMdFilename.
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;
export function setGeminiMdFilename(newFilename: string | string[]): void {
if (Array.isArray(newFilename)) {

View file

@ -19,6 +19,7 @@ import {
import {
setGeminiMdFilename,
DEFAULT_CONTEXT_FILENAME,
DEFAULT_CONTEXT_FILENAMES,
} from '../tools/memoryTool.js';
import { flattenMemory, type HierarchicalMemory } from '../config/memory.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
@ -103,7 +104,7 @@ describe('memoryDiscovery', () => {
afterEach(async () => {
vi.unstubAllEnvs();
// Some tests set this to a different value.
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAME);
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAMES);
// Clean up the temporary directory to prevent resource leaks.
// Use maxRetries option for robust cleanup without race conditions
await fsPromises.rm(testRootDir, {