Skip to content

fix(cli): keep AGENTS.md enabled by default context reset#2082

Merged
LaZzyMan merged 2 commits intoQwenLM:mainfrom
zy6p:fix/2062-preserve-default-agents-context-loading
Mar 6, 2026
Merged

fix(cli): keep AGENTS.md enabled by default context reset#2082
LaZzyMan merged 2 commits intoQwenLM:mainfrom
zy6p:fix/2062-preserve-default-agents-context-loading

Conversation

@zy6p
Copy link
Contributor

@zy6p zy6p commented Mar 4, 2026

TLDR

Fix default context filename reset so AGENTS.md remains effective when settings.context.fileName is not configured.

Dive Deeper

Root cause:

  • In loadCliConfig, when settings.context.fileName is absent, we called:
    • setGeminiMdFilename(getCurrentGeminiMdFilename())
  • getCurrentGeminiMdFilename() returns only the first configured file name.
  • Default state is [QWEN.md, AGENTS.md], but this code collapsed it into only QWEN.md, unintentionally disabling default AGENTS.md loading.

What changed:

  • packages/cli/src/config/config.ts
    • reset defaults using both filenames explicitly:
      • setGeminiMdFilename([DEFAULT_CONTEXT_FILENAME, AGENT_CONTEXT_FILENAME])
  • packages/cli/src/config/config.test.ts
    • added regression test: default path resets to both QWEN.md and AGENTS.md
    • added test: custom settings.context.fileName still overrides as expected

Reviewer Test Plan

  1. Run without context.fileName in settings.
  2. Verify setGeminiMdFilename receives both default names (QWEN.md, AGENTS.md).
  3. Set context.fileName = "CUSTOM_AGENTS.md" and verify custom filename is used.
  4. (Optional behavior check) Create AGENTS.md in project and ensure it is discovered in default configuration.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #2062

Copy link
Collaborator

@LaZzyMan LaZzyMan left a comment

Choose a reason for hiding this comment

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

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}`);
}

@zy6p
Copy link
Contributor Author

zy6p commented Mar 5, 2026

Thanks @LaZzyMan for the detailed review and the two concrete suggestions.

Both points make sense and I will update this PR accordingly:

  1. Replace the fallback in CLI config reset with getAllGeminiMdFilenames() instead of hardcoded defaults.
  2. Update packages/core/src/utils/ignorePatterns.ts to iterate over getAllGeminiMdFilenames() so all context files are excluded.

I’ll include test updates as well in the follow-up commit.

@zy6p
Copy link
Contributor Author

zy6p commented Mar 5, 2026

Implemented in commit d7d2ffb.

Addressed both suggestions:

  1. loadCliConfig fallback now uses getAllGeminiMdFilenames() (instead of hardcoded defaults).
  2. ignorePatterns.ts now excludes all configured context filenames by iterating getAllGeminiMdFilenames().

Also updated tests/mocks accordingly (config.test.ts, ignorePatterns.test.ts).

Thanks again for the review. Please take another look when convenient.

Copy link
Collaborator

@LaZzyMan LaZzyMan left a comment

Choose a reason for hiding this comment

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

LGTM!

@LaZzyMan LaZzyMan merged commit 881bef1 into QwenLM:main Mar 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGENTS.md does not take effect

2 participants