Repository navigation
Add opt-in repository context to reviews (Phase 9, K1–K5) - #21
Closed
ziadantar90 wants to merge 6 commits into
Closed
ziadantar90 wants to merge 6 commits into
ziadantar90 wants to merge 6 commits into
Conversation
Get-RepoContext.ps1 lists the files tracked on the pull request branch with git ls-tree, applies the review excludes, and renders one line per folder with its file names. Over budget it falls back to file counts, shallow folders first, and says how many deeper folders it left out. It reads the pipeline's existing checkout: no clone, no API call. Nothing calls it yet; the review wires it in behind an opt-in setting in a later commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF Signed-off-by: Claude <noreply@anthropic.com>
For the files in a batch, Get-RepoContext.ps1 now finds:
- callers: files on the PR branch that use a function, method, class
or type the batch declares, changes or removes, or whose body changed
(from git's hunk headers). One git grep -w per language family, so a
Go Parse does not match a PowerShell [int]::Parse. Comments, test
helpers, short and generic names, and names used in more than 40
files are skipped.
- imports: files the changed files import, for TS/JS (relative and @/),
Python (relative and absolute), Go (through go.mod), PowerShell
dot-sourcing and Bicep modules. Imports the changed lines use rank
first.
New-BatchRepoContext takes callers and imports in turn, callers first,
as numbered excerpts ('NN | ', unlike the diff's 'NN+ '): the lines
around each use for a caller, the whole file or its declarations for an
import. It stops at the token budget or 12 files and never repeats a
file that is in the batch. Get-CodeChanges keeps each file's hunk
header function names for this.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF
Signed-off-by: Claude <noreply@anthropic.com>
Invoke-LLMCodeReview takes -RepoContext ('false' by default) and
-ContextMaxTokens (12000). When on, each batch gets a "Repository
context" user message before the diff, in its own fence with a random
id, like the diff. The wrapper says the context is untrusted and that
comments must point at a + line in the diff, so a legacy prompt is
covered too; the anchor check already drops anything else.
The context budget comes out of reviewMaxBatchTokens (the diff keeps at
least half), so a request with context is no larger than one without.
A batch that is split in two rebuilds context for each half. If the
repository cannot be read or a batch's context fails, the review goes
on without it. The result reports ContextFiles and ContextTokens.
The base prompt gets a "Using Repository Context" section: check
callers, existing helpers and conventions; never comment on context
files; anchor on the diff line and name the affected place; do not
treat a caller missing from the excerpts as proof there is none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF
Signed-off-by: Claude <noreply@anthropic.com>
stage-template.yml gets two parameters: reviewRepoContext (boolean, default false) and reviewContextMaxTokens (number, default 12000), and passes them to Invoke-LLMCodeReview. The metrics event adds contextFiles and contextTokens (custom fields, so the metrics API needs no change), and the run summary line reports repository context when it was sent. Docs: regenerated parameter reference; SECURITY.md lists repository context in "What the model receives", the prompt-injection measures and the metrics fields; README feature list, configuration table and cost notes; troubleshooting rows for the two context log lines; the example pipeline shows the setting; CHANGELOG entry under Unreleased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF Signed-off-by: Claude <noreply@anthropic.com>
tools/Measure-RepoContext.ps1 builds the review input for two commits with and without repository context and prints the estimated prompt tokens per batch, without calling a model. With -OutputPath it writes each batch's context to a file so it can be read. Measured on this repository's 18 merged pull requests and 10 recent nestjs/nest commits (2,700 files), then tuned: - Large repositories: the map was 3,000 tokens of single-file folder counts. It now shows the top two (or one) folder levels with counts, within min(1500, budget/8), and lists the file names of the changed files' folders per batch instead. - Callers: test, spec, e2e and sample files rank after production code, at most three test files and three files per symbol, and a symbol used in more than 25 files is dropped (was 40). - Imports: ESM TypeScript imports of './x.js' resolve to './x.ts', and imports the changed lines do not use only fill leftover budget. Result at the default 12,000-token budget: prompt tokens +20% in total on this repository (median +10%), +79% on the nestjs sample (median +74%; +54% at a 6,000 budget). Context builds in about a second or less per batch. Review quality needs a live model and is not measured here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF Signed-off-by: Claude <noreply@anthropic.com>
It stays off by default and is not part of a release until a live comparison on real pull requests shows it improves reviews. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8A4vvpSVaT7B5TkFLqmvF Signed-off-by: Claude <noreply@anthropic.com>
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.
Requested by Ziad · project thread
What
A new setting,
reviewRepoContext(defaultfalse), lets the reviewer see code outside the diff. With it on, each batch also gets:The context is read with
gitfrom the checkout the pipeline already makes (fetchDepth: 0). That means no clone, no Azure DevOps API call and no new permission. It is capped byreviewContextMaxTokens(default 12000). That budget comes out ofreviewMaxBatchTokens, so no single request grows.Safety
Commits (one per plan item)
contextFiles/contextTokens, run summary, docs, CHANGELOGtools/Measure-RepoContext.ps1, plus tuning based on the measurementsMeasurements (prompt tokens, estimated; no model called)
Checks
Update-ParameterReference.ps1 -Check: up to dateGenerated by Claude Code