Skip to content

Add RepoContextInjection capability#175

Draft
DouweM wants to merge 1 commit intomainfrom
capability/repo-context-injection
Draft

Add RepoContextInjection capability#175
DouweM wants to merge 1 commit intomainfrom
capability/repo-context-injection

Conversation

@DouweM
Copy link
Copy Markdown
Contributor

@DouweM DouweM commented Apr 10, 2026

Summary

  • Implements RepoContextInjection, an AbstractCapability that discovers and injects repository convention files (AGENTS.md, CLAUDE.md, .cursorrules, .github/copilot-instructions.md, CONVENTIONS.md, CODING_GUIDELINES.md) into the agent's system prompt
  • Walks from root_dir upward to filesystem root, deduplicates symlinks, caches after first scan, and respects a configurable max_total_chars limit
  • Exported as from pydantic_harness import RepoContextInjection

Closes #64

Test plan

  • 25 tests covering discovery, formatting, caching, deduplication, validation, and public import
  • 100% code coverage (branch + line)
  • pyright strict mode passes
  • ruff lint + format passes

🤖 Generated with Claude Code

Implements a capability that discovers and injects repository convention
files (AGENTS.md, CLAUDE.md, .cursorrules, etc.) into the agent's system
prompt via get_instructions(). Walks from root_dir upward, deduplicates
symlinks, caches after first scan, and respects a configurable character
limit.

Closes #64

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment on lines +77 to +78
except OSError:
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 UnicodeDecodeError not caught when reading non-UTF-8 context files

The except OSError at src/pydantic_harness/repo_context_injection.py:77 does not catch UnicodeDecodeError, which inherits from ValueError, not OSError. If a file matching file_patterns (e.g., a binary .cursorrules file or a file in a non-UTF-8 encoding) is encountered, candidate.read_text(encoding='utf-8') at line 76 raises UnicodeDecodeError, which propagates uncaught through _get_context() and get_instructions(), potentially crashing agent construction. The intent of the try/except is to gracefully skip unreadable files, but this encoding error path is missed.

Suggested change
except OSError:
continue
except (OSError, UnicodeDecodeError):
continue
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@DouweM
Copy link
Copy Markdown
Contributor Author

DouweM commented Apr 10, 2026

Originally posted by @DouweM in #154 comment (PR was recreated)

Audit vs prior art: RepoContextInjection

Worth adding now:

  • scan_children option to also discover files in subdirectories
  • Add .aider.conf.yml and .aiderignore to default patterns
  • cache toggle for dynamic refresh in long-running agents

Follow-up opportunities:

  • Git-aware discovery, frontmatter parsing for conditional inclusion

@DouweM
Copy link
Copy Markdown
Contributor Author

DouweM commented Apr 10, 2026

Originally posted by @DouweM in #154 comment (PR was recreated)

Audit vs prior art: RepoContextInjection

Worth adding now:

  • scan_children option to also discover files in subdirectories
  • Add .aider.conf.yml and .aiderignore to default patterns
  • cache toggle for dynamic refresh in long-running agents

Follow-up opportunities:

  • Git-aware discovery, frontmatter parsing

@DouweM DouweM marked this pull request as draft April 10, 2026 15:12
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.

Repository Context Injection (AGENTS.md / conventions loading)

1 participant