Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c99804
feat(review): add OpenJDK repository context
wenshao Aug 2, 2026
0d4fb87
refactor(review): extract repository context foundation
wenshao Aug 3, 2026
4d5ce37
fix(review): repair CI type guard and add manifest repository context
wenshao Aug 3, 2026
78ae250
Merge branch 'main' into feat/review-openjdk-context
wenshao Aug 3, 2026
f27c77d
fix(review): harden repository context per maintainer review
wenshao Aug 3, 2026
b1dd7dc
Merge remote-tracking branch 'origin/main' into feat/review-openjdk-c…
wenshao Aug 3, 2026
0625585
fix(review): skip unsafe related paths in manifest context (#8401)
wenshao Aug 3, 2026
e36195c
Merge branch 'main' into feat/review-openjdk-context
qwen-code-dev-bot Aug 3, 2026
6654180
fix(ci): align review timeout helper test with externalized variables…
qwen-code-dev-bot Aug 3, 2026
fd339d5
Merge remote-tracking branch 'origin/main' into feat/review-openjdk-c…
qwen-code-dev-bot Aug 4, 2026
aeb7bc0
Merge branch 'main' into feat/review-openjdk-context
wenshao Aug 4, 2026
5e3adea
fix(review): harden repository context bounds and base identity reads…
qwen-code-dev-bot Aug 4, 2026
704e9f7
Merge branch 'main' into feat/review-openjdk-context
qwen-code-dev-bot Aug 4, 2026
34ebbac
chore(review): merge origin/main into feat/review-openjdk-context
qwen-code-dev-bot Aug 5, 2026
4bf8dc8
Merge remote-tracking branch 'origin/main' into feat/review-openjdk-c…
qwen-code-dev-bot Aug 5, 2026
e473346
Merge branch 'main' into feat/review-openjdk-context
qwen-code-dev-bot Aug 5, 2026
ba4571d
fix(review): bound manifest matching work and pin round-2 review gaps…
qwen-code-dev-bot Aug 5, 2026
fe06aa1
Merge branch 'main' into feat/review-openjdk-context
qwen-code-dev-bot Aug 5, 2026
a1366d9
fix(test): isolate serve streaming suite from stray workspace setting…
qwen-code-dev-bot Aug 6, 2026
aa8c7cb
fix(review): cap identity reads, bill match work by length, pin round…
qwen-code-dev-bot Aug 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/design/review-repository-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Review repository context

## Problem

The review pipeline needs a bounded way for repositories to declare review guidance without teaching shared roster, prompt, coverage, and composition code about individual projects. Repository metadata is security-sensitive for pull request reviews because the reviewed branch must not be able to opt into or remove trusted context.

## Manifest

A repository may provide strict JSON at `.qwen/review-context.json`:

```json
{
"version": 1,
"label": "Example repository",
"rules": [
{
"paths": ["packages/*/src/**"],
"relatedPaths": ["packages/*/src/**"],
"domains": ["runtime"],
"recommendedTests": ["test:runtime"],
"requiredConfigurations": ["debug"],
"requiredAgents": ["test-matrix"],
"unverifiedDimensions": ["Alternate configuration"],
"verificationNotes": ["Run the repository-native focused tests"]
}
]
}
```

The top-level fields are exactly `version`, `label`, and `rules`. Each rule requires `paths`; all other rule fields are optional. Unknown or missing required fields, comments, unsupported versions, oversized values, control characters, and duplicate array entries are rejected. Arrays are human-authored and may be written in any order; values from all matching rules are merged, deduplicated, and returned sorted and unique (the internal wire format keeps the strict sorted-and-unique check). Rule order is preserved. The total `paths` globs across all rules, the merged `relatedPaths` glob list, and every merged field are capped at the wire bounds and rejected fail-closed, so a matching burst cannot stall the step or outgrow the contract.

`paths` and `relatedPaths` use repository-relative `/`-separated globs. Matching is case-sensitive on every platform and `?` consumes one UTF-16 code unit. The supported metacharacters are `*`, `?`, and a complete `**` path segment. Absolute paths, backslashes, empty or `.`/`..` segments, negation, brace expansion, character classes, and extended glob syntax are rejected.

A rule matches when any changed path matches one of its `paths` globs. If no rule matches, the provider returns no context. A matching rule's deduplicated `relatedPaths` globs are expanded from the worktree with dot files enabled, directory results disabled, symlink traversal disabled, and case-sensitive matching. Related globs containing wildcards must start with a non-wildcard directory segment so expansion cannot begin with a repository-wide wildcard; a completely static entry resolves to itself when it exists as a regular file. Changed paths are removed from the result. Resolved files must remain inside the worktree. Expansion never descends into dependency and build-output trees (`node_modules`, `dist`, and the other conventional names the scan skips) and fails closed when either limit is exceeded: 16384 visited entries across the scan (files and directories, matching or not — calibrated on this repository's installed checkout, so a honestly scoped subtree, including all of `packages/`, never trips it) and 128 resolved files in the result.

## Trust boundary

`repo-context` reads the fixed manifest path through `RepositoryContextProviderInput.readIdentityFile`. For pull request plans, the manifest therefore comes only from the trusted merge-base commit recorded by the fetch stage. The pull request head cannot opt in, opt out, or change the rules. For local plans, the manifest comes from the current worktree after safe-relative-path validation and realpath containment.

Identity reads return the same shape in both modes (CRLF normalised to LF, surrounding whitespace trimmed), and fail closed: an absent file yields `null`, but a file that is present and unreadable throws rather than masquerading as "not this repository". Both modes follow a symlinked identity under the same containment rule, and a directory yields nothing in both. A pull request plan whose merge base never resolved (`mergeBaseSha: null`) — or whose base fetch failed, leaving the recorded sha possibly stale — writes a `null` artifact without consulting the worktree at all: falling back to the worktree would read the manifest from the PR head, the exact read this boundary forbids, and a possibly stale sha is not a trusted source either.

Two residuals are recorded so the guarantee is not overstated. First, for pull request plans the RULES come from the merge base, but `relatedPaths` globs are expanded against the head worktree, so the head still decides which files the base's globs resolve to; impact is low because reviewers read the head tree anyway. Second, local reviews read the manifest from the current worktree, so reviewing an untrusted repository lets that repository put one bounded, control-character-free block of guidance — the label plus six capped arrays, a few hundred kilobytes at the schema bounds — into every code-reviewing brief; the validation bounds and inert rendering are the mitigation.

The manifest provider is statically registered in-process and returns the generic `RepositoryContext` shape with provider `manifest`. Its complete output passes through the shared `validateRepositoryContext` validator before downstream consumers use it. No dynamic plugin registry, shell execution, templates, or opaque payloads are supported.

## Review workflow

Medium- and high-effort local and same-repository pull request reviews invoke `repo-context` after the review plan is captured. The command receives absolute plan, worktree, and output paths. Low-effort reviews and cross-repository lightweight reviews skip repository context because they do not run the full local-tree workflow.

Code-review agents receive the generic context headed by its label. The build-and-test role receives recommended tests, required configurations, and verification notes. Required roles are merged into the normal roster without duplication, and only when the review's effort, topology, and mode already permit them — a manifest cannot inflate a medium review with the adversarial personas, re-add whole-diff walkers to a chunked fan-out, or demand a tree-grepping role from a review with no tree. Composition discloses unverified dimensions as non-blocking proof boundaries; a present-but-invalid context fails every consumer closed rather than being silently dropped anywhere.

Status: this is the foundation — the contract, the command, and the downstream consumers, exercised by unit tests and the review skill. No `.qwen/review-context.json` ships with this change, so nothing beyond tests runs end to end until a repository adopts one.
27 changes: 27 additions & 0 deletions docs/users/features/code-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,33 @@ You can customize review criteria per project. `/review` reads rules from these

Rules are injected into the LLM review agents (0-6) as additional criteria. For PR reviews, rules are read from the **base branch** to prevent a malicious PR from injecting bypass rules.

## Repository Context

Repositories can hand the reviewers bounded, repository-specific guidance by committing a strict JSON manifest to `.qwen/review-context.json`. At medium or high effort, `/review` reads the manifest after capturing the plan and attaches the matching guidance before any agent launches:

```json
{
"version": 1,
"label": "Example repository",
"rules": [
{
"paths": ["packages/*/src/**"],
"domains": ["runtime"],
"relatedPaths": ["packages/runtime/src/**"],
"recommendedTests": ["npm run test:runtime"],
"requiredConfigurations": ["debug"],
"requiredAgents": ["test-matrix"],
"unverifiedDimensions": ["Alternate runtime was not exercised"],
"verificationNotes": ["Use the repository native test runner"]
}
]
}
```

A rule applies when any changed file matches one of its `paths` globs (`*`, `?`, and `**` segments; case-sensitive). All matching rules merge their guidance: domains and related files for the review agents, recommended tests and required configurations for the build-and-test agent, extra reviewer roles (honoured only when the chosen effort and topology run them), and proof boundaries the final review discloses as unverified dimensions. Arrays may be written in any order; duplicate entries are rejected.

For PR reviews the manifest is read from the merge base, so the PR under review cannot opt itself into or out of guidance; local reviews read it from the current worktree. Low-effort and cross-repository reviews skip repository context. The full contract and trust model live in the [design doc](../../design/review-repository-context.md).

## Issue Fidelity

For bugfix PRs, the Issue Fidelity agent fetches issue evidence directly instead of relying on PR description text. It uses `gh pr view <pr> --repo <owner/repo> --json closingIssuesReferences` for GitHub's strong closing-issue metadata, then `gh issue view <number> --repo <issue_owner>/<issue_repo> --json title,body,comments` for the original report and discussion — the `--json` form includes the issue **body** (the reporter's original repro), which `--comments` alone omits, and the issue's own repository is read from each reference (a PR can close an issue in a different repo). This agent runs only for PR targets; local-diff and file-path reviews skip it.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('reviewCommand', () => {
'fetch-pr',
'capture-local',
'plan-diff',
'repo-context',
'pr-context',
'comment-status',
'load-rules',
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { findingsCommand } from './review/findings.js';
import { fetchPrCommand } from './review/fetch-pr.js';
import { captureLocalCommand } from './review/capture-local.js';
import { planDiffCommand } from './review/plan-diff.js';
import { repoContextCommand } from './review/repo-context.js';
import { prContextCommand } from './review/pr-context.js';
import { commentStatusCommand } from './review/comment-status.js';
import { loadRulesCommand } from './review/load-rules.js';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const reviewCommand: CommandModule = {
.command(fetchPrCommand)
.command(captureLocalCommand)
.command(planDiffCommand)
.command(repoContextCommand)
.command(prContextCommand)
.command(commentStatusCommand)
.command(loadRulesCommand)
Expand All @@ -74,7 +76,7 @@ export const reviewCommand: CommandModule = {
.command(cleanupCommand)
.demandCommand(
1,
'Specify a subcommand: run, parse-args, fetch-pr, capture-local, plan-diff, pr-context, comment-status, load-rules, agent-prompt, build-test, base-tree, test-delta, drive, mock-provider, extract-step, script-lint, resolve-anchors, check-coverage, cost-ledger, presubmit, test-efficacy, test-plan, findings, publish-assets, compose-review, save-artifact, submit, or cleanup.',
'Specify a subcommand: run, parse-args, fetch-pr, capture-local, plan-diff, repo-context, pr-context, comment-status, load-rules, agent-prompt, build-test, base-tree, test-delta, drive, mock-provider, extract-step, script-lint, resolve-anchors, check-coverage, cost-ledger, presubmit, test-efficacy, test-plan, findings, publish-assets, compose-review, save-artifact, submit, or cleanup.',
)
.version(false),
handler: () => {
Expand Down
53 changes: 53 additions & 0 deletions packages/cli/src/commands/review/agent-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,59 @@ describe('buildRoleBrief — every agent, not just the territory ones', () => {
expect(p).not.toMatch(/If you find no issues, say/i);
});

it('injects generic repository context into reviewers and a narrow verification boundary into Agent 7', () => {
const contextPlan = {
...PR_PLAN,
repositoryContext: {
version: 1,
provider: 'fake-provider',
label: 'Example project',
domains: ['compiler', 'runtime'],
relatedPaths: ['src/compiler.ts', 'src/runtime.ts'],
recommendedTests: ['test:compiler'],
requiredConfigurations: ['debug', 'linux-x64'],
requiredAgents: ['test-matrix'],
unverifiedDimensions: ['Alternate runtime was not exercised'],
verificationNotes: ['Use the repository native test runner'],
},
};

const reviewerBrief = buildRoleBrief(contextPlan, '1a');
expect(reviewerBrief).toContain('Example project repository context');
expect(reviewerBrief).toContain('compiler, runtime');
expect(reviewerBrief).toContain('src/compiler.ts');
expect(reviewerBrief).toContain('test:compiler');
expect(reviewerBrief).toContain('debug, linux-x64');
expect(reviewerBrief).toContain('Alternate runtime was not exercised');
expect(reviewerBrief).toContain('Use the repository native test runner');

const territoryBrief = buildChunkAgentPrompt(contextPlan, 13);
expect(territoryBrief).toContain('Example project repository context');
expect(territoryBrief).toContain('src/compiler.ts');

const requiredAgentBrief = buildRoleBrief(contextPlan, 'test-matrix');
expect(requiredAgentBrief).toContain('Example project repository context');
expect(requiredAgentBrief).toContain('src/compiler.ts');
expect(requiredAgentBrief).toContain('test:compiler');

const buildBrief = buildRoleBrief(contextPlan, '7');
expect(buildBrief).not.toContain('Example project repository context');
expect(buildBrief).not.toContain('compiler, runtime');
expect(buildBrief).not.toContain('src/compiler.ts');
expect(buildBrief).not.toContain('Alternate runtime was not exercised');
expect(buildBrief).toContain('Repository-specific verification boundary');
expect(buildBrief).toContain('test:compiler');
expect(buildBrief).toContain('debug, linux-x64');
expect(buildBrief).toContain('Use the repository native test runner');

// The --whole-diff path builds Agent 8's briefs; it carries the same
// block, or the one finder launched for a dominant domain is the one
// reviewer denied that domain's guidance.
const wholeDiff = buildWholeDiffBlock(contextPlan);
expect(wholeDiff).toContain('Example project repository context');
expect(wholeDiff).toContain('src/compiler.ts');
});

it('carries the mutation-testing lens into Agent 5, equivalent-mutant escape hatch included', () => {
// The all-role test above proves every brief gets the diff and the format; it
// cannot see whether a *specific* lens reached its role. If prompt assembly
Expand Down
74 changes: 72 additions & 2 deletions packages/cli/src/commands/review/agent-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ import {
scheduleReverseAuditRound,
type RoundSchedule,
} from './lib/retirement.js';
import { BRIEFS, type RoleId } from './lib/agent-briefs.js';
import {
BRIEFS,
isRepositoryContextRoleId,
type RoleId,
} from './lib/agent-briefs.js';
import {
repositoryContextOf,
type RepositoryContext,
} from './lib/repository-context.js';
import { pathRulesFor } from './lib/path-rules.js';
import {
requiredAgents,
Expand Down Expand Up @@ -113,6 +121,7 @@ interface PlanReport {
ownerRepo?: unknown;
worktreePath?: unknown;
mergeBaseSha?: unknown;
repositoryContext?: unknown;
}

/** A heavy file's entry, which is the only kind an invariant agent can be built from. */
Expand Down Expand Up @@ -366,6 +375,11 @@ export function buildChunkAgentPrompt(
parts.push('', '## Project rules', '', rules.trim());
}

const repositoryContext = repositoryContextOf(report);
if (repositoryContext) {
parts.push('', ...repositoryContextBlock(repositoryContext));
}

// Deliberately NOT included: a sentence for the agent to recite when it finds
// nothing. Every real launch handed the agent its own receipt text — `If you
// find no issues, say "No issues found — reviewed chunk 13 (...)"` — and an
Expand Down Expand Up @@ -483,7 +497,13 @@ export function buildWholeDiffBlock(
rules?: string,
): string {
const diffPath = requireDiffPath(report);
return [...diffReadingBlock(report, diffPath), ...tail(rules)].join('\n');
const parts = [...diffReadingBlock(report, diffPath)];
const repositoryContext = repositoryContextOf(report);
if (repositoryContext) {
parts.push('', ...repositoryContextBlock(repositoryContext));
}
parts.push(...tail(rules));
return parts.join('\n');
}

/** The diff path, or the error this whole command exists to make impossible. */
Expand Down Expand Up @@ -724,6 +744,42 @@ function invariantFileBlock(
return parts;
}

function contextList(values: string[]): string[] {
return values.length > 0 ? values.map((value) => `- ${value}`) : ['- (none)'];
}

function repositoryContextBlock(context: RepositoryContext): string[] {
return [
`## ${context.label} repository context`,
'',
`Domains: ${context.domains.join(', ') || '(none)'}`,
'',
'Related paths:',
...contextList(context.relatedPaths),
'',
`Recommended tests: ${context.recommendedTests.join(', ') || '(none)'}`,
`Required configurations: ${context.requiredConfigurations.join(', ') || '(none)'}`,
'',
'Unverified dimensions:',
...contextList(context.unverifiedDimensions),
'',
'Verification notes:',
...contextList(context.verificationNotes),
];
}

function repositoryBuildBoundary(context: RepositoryContext): string[] {
return [
'## Repository-specific verification boundary',
'',
`Recommended tests: ${context.recommendedTests.join(', ') || '(none)'}`,
`Required configurations: ${context.requiredConfigurations.join(', ') || '(none)'}`,
'',
'Verification notes:',
...contextList(context.verificationNotes),
];
}

/**
* The launch prompt for any role that is not a territory agent.
*
Expand Down Expand Up @@ -769,6 +825,20 @@ export function buildRoleBrief(
}

parts.push('## Your dimension', '', brief.brief);
const repositoryContext = repositoryContextOf(report);
if (role === '7') {
if (repositoryContext) {
parts.push('', ...repositoryBuildBoundary(repositoryContext));
}
} else if (
brief.reviewsCode ||
(isRepositoryContextRoleId(role) &&
repositoryContext?.requiredAgents.includes(role))
) {
if (repositoryContext) {
parts.push('', ...repositoryContextBlock(repositoryContext));
}
}

// Cross-repo lightweight mode: there is no tree, only the diff. Two briefs assume
// one, and the degradation used to be a sentence the orchestrator was told to add
Expand Down
Loading
Loading