fix(cli): keep AGENTS.md enabled by default context reset#2082
Conversation
LaZzyMan
left a comment
There was a problem hiding this comment.
Great catch on the root cause! The analysis is spot-on — getCurrentGeminiMdFilename() collapses the array into a single string.
A couple of suggestions:
1. Use getAllGeminiMdFilenames() instead of hardcoding the default array
The current fix hardcodes [DEFAULT_CONTEXT_FILENAME, AGENT_CONTEXT_FILENAME], which duplicates the default value defined in memoryTool.ts. If additional context filenames are added in the future, this code won't automatically pick them up. A more robust approach:
import {
getAllGeminiMdFilenames,
// remove getCurrentGeminiMdFilename if no longer needed
} from '@qwen-code/qwen-code-core';
// in loadCliConfig:
} else {
setServerGeminiMdFilename(getAllGeminiMdFilenames());
}This keeps the single source of truth in memoryTool.ts.
2. There's a similar issue in packages/core/src/utils/ignorePatterns.ts
ignorePatterns.ts also uses getCurrentGeminiMdFilename() to build file exclusion patterns (line 163):
patterns.push(`**/${getCurrentGeminiMdFilename()}`);This means AGENTS.md is not excluded from tool scan results (e.g., read_many_files, glob search), causing its content to potentially appear twice in the model's context — once from system memory loading and once from tool output. It should iterate over getAllGeminiMdFilenames() to exclude all configured context files:
for (const filename of getAllGeminiMdFilenames()) {
patterns.push(`**/${filename}`);
}|
Thanks @LaZzyMan for the detailed review and the two concrete suggestions. Both points make sense and I will update this PR accordingly:
I’ll include test updates as well in the follow-up commit. |
|
Implemented in commit d7d2ffb. Addressed both suggestions:
Also updated tests/mocks accordingly ( Thanks again for the review. Please take another look when convenient. |
TLDR
Fix default context filename reset so
AGENTS.mdremains effective whensettings.context.fileNameis not configured.Dive Deeper
Root cause:
loadCliConfig, whensettings.context.fileNameis absent, we called:setGeminiMdFilename(getCurrentGeminiMdFilename())getCurrentGeminiMdFilename()returns only the first configured file name.[QWEN.md, AGENTS.md], but this code collapsed it into onlyQWEN.md, unintentionally disabling defaultAGENTS.mdloading.What changed:
packages/cli/src/config/config.tssetGeminiMdFilename([DEFAULT_CONTEXT_FILENAME, AGENT_CONTEXT_FILENAME])packages/cli/src/config/config.test.tsQWEN.mdandAGENTS.mdsettings.context.fileNamestill overrides as expectedReviewer Test Plan
context.fileNamein settings.setGeminiMdFilenamereceives both default names (QWEN.md,AGENTS.md).context.fileName = "CUSTOM_AGENTS.md"and verify custom filename is used.AGENTS.mdin project and ensure it is discovered in default configuration.Testing Matrix
Linked issues / bugs
Fixes #2062