feat(context): compose context files instead of first-match-wins - #2846
Open
Mibayy wants to merge 2 commits into
Open
feat(context): compose context files instead of first-match-wins#2846Mibayy wants to merge 2 commits into
Mibayy wants to merge 2 commits into
Conversation
build_context_files_prompt() now loads all present primary context sources (.hermes.md, AGENTS.md, CLAUDE.md) and concatenates them, rather than stopping at the first match. Behaviour change: - Projects with both .hermes.md and AGENTS.md now get both - Projects migrating from Cursor keep .cursorrules until they add a primary source (AGENTS.md / .hermes.md) - Shared 20,000-char budget is distributed proportionally when the combined content would exceed it - .cursorrules is a pure fallback: skipped when any primary source is present (backward-compatible for cursor-only projects) - Single-source projects behave exactly as before Closes NousResearch#2835
13 tasks
This was referenced Apr 15, 2026
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the focused proposal. The reported behavior is still present on current main: build_context_files_prompt() uses the first-successful loader chain at agent/prompt_builder.py:1976-1982.
Problems
- This is a reversal of an intentional design, not merely an omitted composition step. Commit
2da79b13dfae6476c8a0c268b2ea9ac7cd91a665explicitly replaced prior composition because it could bloat the system prompt with redundant or conflicting instructions. Maintainer agreement is needed on the new conflict-resolution contract. - The proposed fixed 20,000-character aggregate cap does not preserve current main's cap contract.
agent/prompt_builder.py:1201-1219resolves an explicit configured cap or a model-window-derived dynamic cap, andagent/system_prompt.py:451-453passescontext_lengthinto the builder. - The PR changes documented behavior but omits updates to
website/docs/user-guide/features/context-files.md:109,website/docs/user-guide/configuration.md:1973, andwebsite/docs/developer-guide/prompt-assembly.md:188.
Suggested changes
- Preserve the current
context_lengthflow and resolve one aggregate budget through_get_context_file_max_chars(context_length). - Add aggregate-budget tests for explicit configuration and dynamic-cap cases, then update the affected documentation.
Automated hermes-sweeper review.
| if primary_parts: | ||
| # Distribute the shared budget proportionally across all present sources | ||
| total_chars = sum(len(p) for p in primary_parts) | ||
| if total_chars > CONTEXT_FILE_MAX_CHARS: |
Contributor
There was a problem hiding this comment.
Current main no longer has a fixed context-file cap: agent/prompt_builder.py:1201-1219 resolves context_file_max_chars or a model-window-derived budget, and the builder receives context_length. A salvage should preserve that flow and derive the aggregate budget through _get_context_file_max_chars(context_length) rather than hard-coding 20,000.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2835
Problem
build_context_files_prompt()used anor-chain that silently dropped every context file after the first match. A project with both.hermes.mdandAGENTS.mdwould never see the second one.Solution
Load all present primary sources and concatenate them. A shared 20,000-char budget is distributed proportionally when the combined content would exceed it.
New composition order:
.hermes.md/HERMES.mdAGENTS.md/agents.mdCLAUDE.md/claude.md.cursorrules/.cursor/rules/Backward compatibility
.cursorrules, noAGENTS.md): identical behavior