Skip to content

feat: support configured external context files - #48809

Open
RoySRose wants to merge 1 commit into
NousResearch:mainfrom
RoySRose:feat/context-external-files
Open

feat: support configured external context files#48809
RoySRose wants to merge 1 commit into
NousResearch:mainfrom
RoySRose:feat/context-external-files

Conversation

@RoySRose

@RoySRose RoySRose commented Jun 19, 2026

Copy link
Copy Markdown

Summary

  • Add context.external_files to inject configured project context files in deterministic order.
  • Add context.ignore_hermes_md so deployments can avoid HERMES.md shadowing AGENTS.md.
  • Reuse existing context scanning/truncation and de-duplicate external files against automatic discovery.
  • Clarify the docs/code behavior around AGENTS.md: current automatic discovery loads AGENTS.md from the active working directory only; explicit hierarchies can now be configured with context.external_files.

Motivation

Some resident Hermes deployments keep canonical agent context outside the active terminal cwd or need a root → scope → agent context chain. This makes that wiring explicit in config instead of relying on a single auto-discovered HERMES.md/AGENTS.md file.

Note: the existing docs said AGENTS.md was hierarchical/recursive, but the current implementation and tests say otherwise (_load_agents_md() is cwd-only and test_agents_md_top_level_only asserts subdirectory copies are ignored). This PR does not silently add recursive auto-discovery; it adds an explicit, ordered config mechanism for deployments that want a hierarchy.

Test plan

  • uv run python -m pytest tests/agent/test_prompt_builder.py tests/hermes_cli/test_config.py tests/tools/test_threat_patterns.py -o 'addopts=' -q
  • uv run ruff check agent/prompt_builder.py hermes_cli/config.py tests/agent/test_prompt_builder.py tests/hermes_cli/test_config.py tools/threat_patterns.py

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 19, 2026
@RoySRose
RoySRose force-pushed the feat/context-external-files branch from 7bfeaa9 to 3e77bff Compare June 19, 2026 04:18

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

  • 6 files changed, +242/-14 lines — adds configurable external context file support
  • Loads context.external_files from config.yaml with proper error handling
  • Well-structured with path normalization and de-duplication; no security concerns

Reviewed by Hermes Agent

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing a real limitation: current agent/prompt_builder.py:1947-1984 only loads automatic cwd context sources, so configured external context is not already implemented.

Problems

  • tools/threat_patterns.py:55 weakens the hidden-comment scanner. The added \b boundary does not match underscore-delimited tokens, so <!-- system_prompt: ... --> and <!-- ignore_rules: ... --> bypass this detector; current main blocks the former with html_comment_injection (tools/threat_patterns.py:69).
  • The claimed automatic de-duplication is incomplete. agent/prompt_builder.py:1900-1908 excludes configured paths for .hermes.md, AGENTS.md, and CLAUDE.md, but not _load_cursorrules(). Configuring a cwd .cursorrules or .cursor/rules/*.mdc file loads it twice.
  • Salvage must preserve the current context.engine setting (hermes_cli/config.py:2171-2173) while adding these keys; the PR's separate context mapping predates that schema.

Suggested changes

  • Preserve detection for underscore-delimited hidden-comment instruction tokens and add regressions.
  • Pass exclusions through cursor-rule discovery and test both cursor-rule forms.
  • Merge the settings into the existing context mapping and update the dedicated context-file docs.

The June 27 cross-reference to open PR #53766 is overlapping work, not implementation on main. This is an automated hermes-sweeper review.

Comment thread tools/threat_patterns.py
(r'disregard\s+(?:\w+\s+)*(your|all|any)\s+(?:\w+\s+)*(instructions|rules|guidelines)', "disregard_rules", "all"),
(r'act\s+as\s+(if|though)\s+(?:\w+\s+)*you\s+(?:\w+\s+)*(have\s+no|don\'t\s+have)\s+(?:\w+\s+)*(restrictions|limits|rules)', "bypass_restrictions", "all"),
(r'<!--[^>]*(?:ignore|override|system|secret|hidden)[^>]*-->', "html_comment_injection", "all"),
(r'<!--[^>]*\b(?:ignore|override|system|secret|hidden)\b[^>]*-->', "html_comment_injection", "all"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking: \b treats _ as a word character, so hidden comments such as <!-- system_prompt: ... --> and <!-- ignore_rules: ... --> no longer match. Keep the benign ECOSYSTEM-MAP case without losing detection of underscore-delimited instruction tokens, and add regression coverage.

Comment thread agent/prompt_builder.py
if external_context:
sections.append(external_context)

# Priority-based project context: first match wins. Configured external

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This de-duplication claim is not true for .cursorrules or .cursor/rules/*.mdc: the call at line 1908 does not receive external_paths. A configured cursor rule in the cwd will be injected externally and again by automatic discovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants