Skip to content

feat(context): compose context files instead of first-match-wins - #2849

Closed
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:feat/compose-context-files-clean
Closed

feat(context): compose context files instead of first-match-wins #2849
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:feat/compose-context-files-clean

Conversation

@dlkakbs

@dlkakbs dlkakbs commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

build_context_files_prompt() used an or-chain that silently dropped every context file after the first match. A project with both .hermes.md andAGENTS.md would only ever load .hermes.md -AGENTS.md was never seen by the agent.

This PR makes context files composable: all present primary sources are loaded and concatenated. Each file keeps its own independent 20k char cap rather than distributing a shared budget proportionally (#2846)This avoids penalizing large files when fewer sources are present - a project with only two context files still gets up to 20k each, not 10k.

.cursorrules remains a pure fallback and is only loaded when none of the primary sources are present.

Related Issue

Fixes #2835

Type of Change

  • New feature (non-breaking change that adds functionality)

Changes Made

  • agent/prompt_builder.py — replaced or-chain in build_context_files_prompt() with explicit composition; .cursorrules loaded only when no primary files are present
  • tests/agent/test_prompt_builder.py — updated 3 tests that asserted first-match-wins behavior; added composition assertions

How to Test

  1. Create a project with both .hermes.md and AGENTS.md
  2. Run hermes in that directory
  3. Verify both files appear in the system prompt context
  4. Create a project with only .cursorrules (no .hermes.md, AGENTS.md, orCLAUDE.md)
  5. Verify .cursorrules still loads as before

Checklist

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (feat(context):)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature
  • I've run pytest tests/ -q and all tests pass (95 passed, 1 pre-existing failure unrelated to this change)
  • I've added tests for my changes
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant docstrings — updatedbuild_context_files_prompt() docstring to reflect new behavior
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact — N/A (pure Python path handling, no OS-specific code)
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

Load all present context files (hermes.md, AGENTS.md, CLAUDE.md) together
instead of stopping at the first match. Each file is still independently
capped at 20k chars. .cursorrules remains a fallback and is only loaded
when none of the above are present.

Closes NousResearch#2835
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution, @dlkakbs!

Closing this as a duplicate of #2846 (by @Mibayy), which targets the same fix/feature. We're consolidating on that PR for review.

If you want to help push it over the line, please jump in there — or if you think your approach is better for a specific reason that isn't covered in the other PR, let us know and we can reopen.

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.

Compose context files instead of first-match-wins

2 participants