Introduce a way to load external content when an agent review code#6128
Open
padenot wants to merge 6 commits into
Open
Introduce a way to load external content when an agent review code#6128padenot wants to merge 6 commits into
padenot wants to merge 6 commits into
Conversation
Introduce ExternalContent as the common loader for review-time files fetched over HTTP. It strips frontmatter, caches the fetched body, and reports load failures with context. The loader uses a shared retrying fetch helper so skills and future review-context content use the same network behavior.
Add a stdlib-only schema parser for review-context.toml, including reusable predicate definitions, boolean composition, file predicates, metadata predicates, and file or revision load actions. The validator rejects unknown fields and malformed rules before the runtime loader sees them, and exposes bugbug-validate-review-context for repository-side checks.
Add the initial review-context runtime: fetch review-context.toml from GitHub, match rules against changed files, deduplicate load actions, and inject fetched files with an audit manifest. Cross-repository file loads are restricted to the rule repository unless explicitly allow-listed, and the parsed rules file is cached briefly to avoid repeated fetches during adjacent reviews.
Extend review-context matching with Bugzilla component lookup for patches that have an associated bug, failing closed when metadata is unavailable. Also implement fetch_revision actions for Phabricator revisions and GitHub commits so rules can include trusted related diffs as review context.
Thread review_context_repo, review_context_branch, extra_context_toml, and content overrides through the CodeReviewTool. When matching rules load content, the prompt receives the formatted external context and the tool response records the content manifest for auditing.
Add developer and rule-author documentation for review-context.toml, including validation, matching semantics, trust policy, metadata predicates, fetch_revision, testing overrides, and prompt injection. The example TOML demonstrates the intended full rule language separately from the subset currently active in the loader, and the docs examples are covered by tests to keep them valid.
Comment on lines
+222
to
+229
| async def run( | ||
| self, | ||
| patch: Patch, | ||
| review_context_repo: Optional[str] = None, | ||
| review_context_branch: str = "main", | ||
| extra_context_toml: Optional[str] = None, | ||
| content_overrides: Optional[dict[str, str]] = None, | ||
| ) -> CodeReviewToolResponse: |
Member
There was a problem hiding this comment.
The run method should stay as it is (i.e., run(self, patch: Patch)) to not break the interface, which we use in the extermination pipeline as well.
Comment on lines
+153
to
+167
| async def get_bug_component(bug_id: int) -> str | None: | ||
| """Return 'Product::Component' for the given Bugzilla bug, or None on failure.""" | ||
| from libmozdata.bugzilla import Bugzilla | ||
|
|
||
| def _fetch() -> str | None: | ||
| bugs: list[dict] = [] | ||
| Bugzilla( | ||
| bug_id, | ||
| include_fields=["product", "component"], | ||
| bughandler=lambda bug, data: data.append(bug), | ||
| bugdata=bugs, | ||
| ).get_data().wait() | ||
| if not bugs: | ||
| return None | ||
| return f"{bugs[0]['product']}::{bugs[0]['component']}" |
Member
There was a problem hiding this comment.
We could get that from the patch class instead of fetching the bug here.
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.
See the doc and example in the last commit first.