feat: support configured external context files - #48809
Conversation
7bfeaa9 to
3e77bff
Compare
tonydwb
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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:55weakens the hidden-comment scanner. The added\bboundary does not match underscore-delimited tokens, so<!-- system_prompt: ... -->and<!-- ignore_rules: ... -->bypass this detector; current main blocks the former withhtml_comment_injection(tools/threat_patterns.py:69).- The claimed automatic de-duplication is incomplete.
agent/prompt_builder.py:1900-1908excludes configured paths for.hermes.md,AGENTS.md, andCLAUDE.md, but not_load_cursorrules(). Configuring a cwd.cursorrulesor.cursor/rules/*.mdcfile loads it twice. - Salvage must preserve the current
context.enginesetting (hermes_cli/config.py:2171-2173) while adding these keys; the PR's separatecontextmapping 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.
| (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"), |
There was a problem hiding this comment.
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.
| if external_context: | ||
| sections.append(external_context) | ||
|
|
||
| # Priority-based project context: first match wins. Configured external |
There was a problem hiding this comment.
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.
Summary
context.external_filesto inject configured project context files in deterministic order.context.ignore_hermes_mdso deployments can avoidHERMES.mdshadowingAGENTS.md.AGENTS.md: current automatic discovery loadsAGENTS.mdfrom the active working directory only; explicit hierarchies can now be configured withcontext.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.mdfile.Note: the existing docs said
AGENTS.mdwas hierarchical/recursive, but the current implementation and tests say otherwise (_load_agents_md()is cwd-only andtest_agents_md_top_level_onlyasserts 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=' -quv 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