Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 8 additions & 0 deletions docs/users/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ Settings are organized into categories. Most settings should be placed within th
| `output.format` | string | The format of the CLI output. | `"text"` | `"text"`, `"json"` |
| `output.showTimestamps` | boolean | Show an `[HH:MM:SS]` timestamp before each assistant response. | `false` | |

#### review

| Setting | Type | Description | Default |
| -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
| `review.attribution` | boolean | Append the attribution footer naming the model and CLI version (e.g. `_— qwen3-coder via Qwen Code /review (v0.21.2)_`) to review bodies and inline comments posted by `/review`. Disable to post reviews without AI attribution. | `true` |
| `review.effort` | enum | Default effort for `/review` when `--effort` is not given: `"low"`, `"medium"`, `"high"`, or `"auto"` (the built-in rule: high for PRs, medium for local changes). An explicit `--effort` wins; an effective `--comment` still forces high and `--fix` still floors at medium. | `"auto"` |
| `review.comment` | boolean | Treat every PR `/review` as if `--comment` was passed: findings are posted to the pull request without the flag. The post still binds to the PR named in the invocation. Enable only if you always want reviews published. | `false` |

#### ui

| Setting | Type | Description | Default |
Expand Down
2 changes: 1 addition & 1 deletion docs/users/features/code-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Or, after running `/review 123`, type `post comments` to publish findings withou
- Where the fix is a single localized edit, a ` ```suggestion ` block you can apply in one click
- For Approve/Request changes verdicts: a review summary with the verdict
- For Comment verdict with all inline comments posted: no separate summary (inline comments are sufficient)
- Model and CLI version attribution footer on each comment (e.g., _— qwen3-coder via Qwen Code /review (v0.21.2)_)
- Model and CLI version attribution footer on each comment (e.g., _— qwen3-coder via Qwen Code /review (v0.21.2)_); set `review.attribution` to `false` in `settings.json` to post without it

**What stays terminal-only:**

Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/commands/review/compose-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ vi.mock('../../utils/stdioHelpers.js', () => ({
vi.mock('../../utils/version.js', () => ({
getCliVersion: vi.fn().mockResolvedValue('0.21.2'),
}));
// The handler reads `review.attribution` from the operator's real
// settings.json — pin it, or a developer running with the switch off
// reddens every handler-level footer assertion below.
vi.mock('../../config/settings.js', async (importOriginal) => {
const actual =
await importOriginal<typeof import('../../config/settings.js')>();
return {
...actual,
loadSettings: vi.fn(() => ({ merged: {} })),
};
});
import { writeStdoutLine, writeStderrLine } from '../../utils/stdioHelpers.js';

const runComposeReviewCommand = (argv: unknown): Promise<void> =>
Expand Down Expand Up @@ -424,6 +435,12 @@ describe('composeReview — the C/S table', () => {
).toBe(true);
});

it('omits the footer entirely when attribution is off', () => {
const r = composeReview(base({}), '0.21.2', false);
expect(r.body).toBe('No issues found. LGTM! ✅');
expect(r.body).not.toContain(MODEL);
});

it('C=0, S≥1 → COMMENT with the no-blockers opener', () => {
const r = composeReview(base({ suggestionsInline: 2 }));
expect(r.event).toBe('COMMENT');
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/commands/review/compose-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
isFooterSafeModelId,
reviewFooter,
} from './lib/review-footer.js';
import { loadSettings } from '../../config/settings.js';

export type ReviewEvent = 'APPROVE' | 'REQUEST_CHANGES' | 'COMMENT';

Expand Down Expand Up @@ -483,8 +484,9 @@ function toBool(value: unknown, field: string): boolean {
export function composeReview(
input: ComposeReviewInput,
cliVersion = 'unknown',
attribution = true,
): ComposeReviewResult {
const result = composeReviewBody(input, cliVersion);
const result = composeReviewBody(input, cliVersion, attribution);
// The ledger marker rides the body THIS function returns, because this — not
// the CLI handler — is what `submit` calls and posts. Appending it in the
// handler left the feature inert end to end: the marker reached only the
Expand Down Expand Up @@ -548,6 +550,7 @@ function ledgerMarkerFor(input: ComposeReviewInput): string | null {
function composeReviewBody(
input: ComposeReviewInput,
cliVersion: string,
attribution: boolean,
): ComposeReviewResult {
const criticalsInline = toCount(input.criticalsInline, 'criticalsInline');
const suggestionsInline = toCount(
Expand Down Expand Up @@ -1154,7 +1157,7 @@ function composeReviewBody(
}
}

const footer = reviewFooter(modelId, cliVersion);
const footer = attribution ? reviewFooter(modelId, cliVersion) : '';
Comment thread
wenshao marked this conversation as resolved.
Resolved
// Bilingual rendering: when the plan (fetch-pr's report) says the PR
// description contains Han characters, the posted body carries the complete
// Chinese version collapsed under the English one — the shape this repo's
Expand All @@ -1174,7 +1177,7 @@ function composeReviewBody(
bilingual && zh !== en
? `${en}\n\n<details>\n<summary>中文说明</summary>\n\n${zh}\n\n</details>`
: en;
return `${text}\n\n${footer}`;
return footer === '' ? text : `${text}\n\n${footer}`;
};

// Clause 6 — scope nobody reviewed. Legal on COMMENT and (alongside body
Expand Down Expand Up @@ -2311,6 +2314,7 @@ export const composeReviewCommand: CommandModule = {
// compose time — a shared runner can rewrite the install mid-session.
footerVersion(process.env['QWEN_CODE_STARTUP_VERSION']) ??
(await getCliVersion()),
loadSettings().merged.review?.attribution ?? true,
Comment thread
wenshao marked this conversation as resolved.
Resolved
);
// The exact terminal verdict, persisted beside the fields it is computed
// from. `event` + `cappedBy` alone cannot reconstruct it — a presubmit
Expand Down
22 changes: 16 additions & 6 deletions packages/cli/src/commands/review/lib/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export interface WriteAuthorizationRequest {
* this session, for this review to be published.
*/
userAuthorized: boolean;
/**
* The standing `review.comment` setting, resolved by the caller from
* settings. When on, a PR review is treated as if `--comment` was passed —
* the target binding below still applies, so the write remains authorised
* only for the PR the recorded arguments name.
*/
defaultComment?: boolean;
/**
* Test seam only (there is no session id under vitest). Ignored whenever a
* session id is present — honouring a caller-supplied path in a real run
Expand Down Expand Up @@ -79,11 +86,12 @@ export interface WriteAuthorizationRequest {
}

/**
* Exactly two things authorise a public write, and both are facts rather than
* Exactly three things authorise a public write, and all are facts rather than
* impressions: `--comment` in the arguments the user typed (re-parsed from the
* CLI's verbatim record), or `--user-authorized`. Authorisation is for a
* *target*, not a mood: the recorded arguments must name the same pull request
* (and, for a URL target, the same repo and host) as the write being attempted.
* CLI's verbatim record), the standing `review.comment` setting, or
* `--user-authorized`. Authorisation is for a *target*, not a mood: the
* recorded arguments must name the same pull request (and, for a URL target,
* the same repo and host) as the write being attempted.
*/
export function reviewWriteAuthorization(req: WriteAuthorizationRequest): {
ok: boolean;
Expand All @@ -110,7 +118,7 @@ export function reviewWriteAuthorization(req: WriteAuthorizationRequest): {
};
}

const verdict = parseReviewArgs(raw);
const verdict = parseReviewArgs(raw, { comment: req.defaultComment });
Comment thread
wenshao marked this conversation as resolved.
Resolved
if (!verdict.comment.effective) {
return {
ok: false,
Expand Down Expand Up @@ -167,6 +175,8 @@ export function reviewWriteAuthorization(req: WriteAuthorizationRequest): {

return {
ok: true,
why: `\`--comment\` was in the review arguments for #${authorisedPr}`,
why: verdict.comment.requested
? `\`--comment\` was in the review arguments for #${authorisedPr}`
: `\`review.comment\` is enabled in settings, and the review arguments name #${authorisedPr}`,
};
}
71 changes: 71 additions & 0 deletions packages/cli/src/commands/review/parse-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ vi.mock('../../utils/stdioHelpers.js', () => ({
writeStderrLineSafe: vi.fn(),
}));

// The handler resolves `review.effort` / `review.comment` from the operator's
// real settings.json — pin it empty, or a developer running with either set
// reddens the wiring tests below.
vi.mock('../../config/settings.js', async (importOriginal) => {
const actual =
await importOriginal<typeof import('../../config/settings.js')>();
return {
...actual,
loadSettings: vi.fn(() => ({ merged: {} })),
};
});

describe('tokenizeArgs', () => {
it('splits on whitespace and collapses runs', () => {
expect(tokenizeArgs(' 6711 --comment ')).toEqual(['6711', '--comment']);
Expand Down Expand Up @@ -324,6 +336,65 @@ describe('parseReviewArgs', () => {
});
});

describe('parseReviewArgs — settings-provided defaults', () => {
it('applies the configured effort when --effort is absent', () => {
const got = parseReviewArgs('6711', { effort: 'medium' });
expect(got.effort).toBe('medium');
expect(got.effortSource).toBe('configured');
});

it('an explicit --effort beats the configured default', () => {
const got = parseReviewArgs('6711 --effort low', { effort: 'medium' });
expect(got.effort).toBe('low');
expect(got.effortSource).toBe('explicit');
});

it('an effective --comment still forces high over the configured effort', () => {
const got = parseReviewArgs('6711 --comment', { effort: 'low' });
expect(got.effort).toBe('high');
expect(got.effortSource).toBe('forced-by-comment');
});

it('an effective --fix still floors the configured effort at medium', () => {
const got = parseReviewArgs('--fix', { effort: 'low' });
expect(got.effort).toBe('medium');
expect(got.effortSource).toBe('forced-by-fix');
});

it('the standing comment setting makes comment effective on a PR target', () => {
const got = parseReviewArgs('6711', { comment: true });
expect(got.comment.requested).toBe(false);
expect(got.comment.effective).toBe(true);
// The PR default is already high, so there is nothing to force.
expect(got.effort).toBe('high');
expect(got.effortSource).toBe('default');
});

it('the standing comment setting forces high over a configured lower effort', () => {
const got = parseReviewArgs('6711', { comment: true, effort: 'low' });
expect(got.comment.effective).toBe(true);
// Posting still requires a verified review — and the warning says it was
// the setting, not a flag the user never typed.
expect(got.effort).toBe('high');
expect(got.effortSource).toBe('forced-by-comment');
expect(got.warnings.some((w) => w.includes('review.comment'))).toBe(true);
});

it('the standing comment setting stays inert on a local target', () => {
const got = parseReviewArgs('', { comment: true });
expect(got.comment.effective).toBe(false);
expect(got.effort).toBe('medium');
expect(got.effortSource).toBe('default');
expect(got.warnings).toHaveLength(0);
});

it('a configured effort above the built-in default applies to local targets', () => {
const got = parseReviewArgs('', { effort: 'high' });
expect(got.effort).toBe('high');
expect(got.effortSource).toBe('configured');
});
});

describe('parseReviewArgs — `--fix` is `--comment` reflected: it needs a tree, not a PR', () => {
// The two flags are gated on opposite targets, and each is *ignored with a
// warning* on the other's. A PR review's tree is the ephemeral worktree Step 9
Expand Down
72 changes: 62 additions & 10 deletions packages/cli/src/commands/review/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
writeStdoutLine,
writeStderrLineSafe,
} from '../../utils/stdioHelpers.js';
import { loadSettings } from '../../config/settings.js';
import { bundleStalenessNotices } from './lib/stale-bundle.js';

export type ReviewEffort = 'low' | 'medium' | 'high';
Expand All @@ -45,11 +46,19 @@ export interface ParsedReviewArgs {
target: ReviewTarget;
/** Resolved effort after defaults and the `--comment` override. */
effort: ReviewEffort;
effortSource: 'explicit' | 'default' | 'forced-by-comment' | 'forced-by-fix';
effortSource:
| 'explicit'
| 'configured'
| 'default'
| 'forced-by-comment'
| 'forced-by-fix';
comment: {
/** `--comment` appeared in the arguments. */
requested: boolean;
/** `--comment` applies (the target is a PR). */
/**
* `--comment` applies (the target is a PR and it was requested — by the
* flag, or by the standing `review.comment` setting).
*/
effective: boolean;
};
/**
Expand Down Expand Up @@ -179,12 +188,28 @@ function classifyToken(token: string): ReviewTarget | 'invalid-url' | null {
return { type: 'file', path: token };
}

export function parseReviewArgs(raw: string): ParsedReviewArgs {
export function parseReviewArgs(
raw: string,
defaults: {
/**
* The standing default from `review.effort` (already resolved out of
* `auto`), applied when no `--effort` flag is present. An explicit flag
* still wins; the `--comment`/`--fix` forcings still override it.
*/
effort?: ReviewEffort;
/**
* The standing `review.comment` setting: treat a PR review as if
* `--comment` was passed. The target binding is untouched — the run still
* authorises only the PR the arguments name.
*/
comment?: boolean;
} = {},
): ParsedReviewArgs {
const tokens = tokenizeArgs(raw);
const warnings: string[] = [];
const unknownFlags: string[] = [];

let commentRequested = false;
let commentRequestedByFlag = false;
let fixRequested = false;
let explicitEffort: ReviewEffort | null = null;

Expand Down Expand Up @@ -216,7 +241,7 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {
const token = tokens[i];

if (token === '--comment') {
commentRequested = true;
commentRequestedByFlag = true;
continue;
}

Expand Down Expand Up @@ -315,8 +340,9 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {

const isPr = target.type === 'pr-number' || target.type === 'pr-url';

const commentRequested = commentRequestedByFlag || defaults.comment === true;
const commentEffective = commentRequested && isPr;
if (commentRequested && !isPr) {
if (commentRequestedByFlag && !isPr) {
warnings.push(
'Warning: `--comment` flag is ignored because the review target is not a PR.',
);
Expand All @@ -339,6 +365,9 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {
if (explicitEffort !== null) {
effort = explicitEffort;
effortSource = 'explicit';
} else if (defaults.effort !== undefined) {
effort = defaults.effort;
effortSource = 'configured';
} else {
effort = isPr ? 'high' : 'medium';
effortSource = 'default';
Expand All @@ -349,7 +378,9 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {
effort = 'high';
effortSource = 'forced-by-comment';
warnings.push(
'`--comment` requires a verified review; running at high effort.',
commentRequestedByFlag
? '`--comment` requires a verified review; running at high effort.'
: '`review.comment` is enabled in settings; posting requires a verified review — running at high effort.',
);
}
// Editing the user's files on the strength of an unverified finding is the
Expand Down Expand Up @@ -379,7 +410,9 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {
? '`--comment` forces high effort'
: effortSource === 'forced-by-fix'
Comment thread
wenshao marked this conversation as resolved.
Resolved
? '`--fix` forces at least medium effort'
: 'using the default effort';
: effortSource === 'configured'
? 'using the configured review.effort'
: 'using the default effort';
for (const issue of effortIssues) {
switch (issue.kind) {
case 'invalid-eq':
Expand Down Expand Up @@ -409,7 +442,7 @@ export function parseReviewArgs(raw: string): ParsedReviewArgs {
target,
effort,
effortSource,
comment: { requested: commentRequested, effective: commentEffective },
comment: { requested: commentRequestedByFlag, effective: commentEffective },
fix: { requested: fixRequested, effective: fixEffective },
extraTokens,
unknownFlags,
Expand All @@ -423,6 +456,25 @@ interface ParseArgsCliArgs {
out: string | undefined;
}

/**
* The standing defaults from `settings.json` (`review.effort`,
* `review.comment`), resolved for `parseReviewArgs`: `auto` effort means the
* built-in rule, so it maps to undefined.
*/
function reviewDefaultsFromSettings(): {
effort?: ReviewEffort;
comment?: boolean;
} {
const review = loadSettings().merged.review;
return {
effort:
review?.effort !== undefined && review.effort !== 'auto'
Comment thread
wenshao marked this conversation as resolved.
Resolved
? review.effort
: undefined,
Comment thread
wenshao marked this conversation as resolved.
Resolved
comment: review?.comment ?? false,
};
}

export const parseArgsCommand: CommandModule = {
command: 'parse-args [raw]',
describe:
Expand Down Expand Up @@ -488,7 +540,7 @@ export const parseArgsCommand: CommandModule = {
writeStderrLineSafe(bundleNotice);
}

const parsed = parseReviewArgs(rawStr);
const parsed = parseReviewArgs(rawStr, reviewDefaultsFromSettings());
Comment thread
wenshao marked this conversation as resolved.
Resolved
const json = JSON.stringify(parsed, null, 2);
if (out) {
mkdirSync(dirname(out), { recursive: true });
Expand Down
Loading
Loading