Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
6c13ef1
feat(review): report findings to clients as a typed contract
wenshao Aug 23, 2026
c367689
fix(i18n): cover report_findings in tool display-name maps
wenshao Aug 23, 2026
c4a3c4f
test(cli): pin ToolMessage routing for findings_list displays
wenshao Aug 23, 2026
27464e1
fix(review): address automatic-review round 1 on the findings contract
wenshao Aug 23, 2026
e58061d
Merge remote-tracking branch 'origin/main' into feat/report-findings-…
qwen-code-ci-bot Aug 23, 2026
75fef65
test(core): pin code-unit file/id sort order in report_findings
qwen-code-ci-bot Aug 23, 2026
dd07bdf
Merge remote-tracking branch 'origin/main' into feat/report-findings-…
qwen-code-ci-bot Aug 23, 2026
6440c42
Merge remote-tracking branch 'origin/main' into feat/report-findings-…
wenshao Aug 23, 2026
f7fcd44
Merge remote-tracking branch 'origin/main' into feat/report-findings-…
wenshao Aug 24, 2026
0080eeb
Merge remote-tracking branch 'origin/main' into feat/report-findings-…
qwen-code-ci-bot Aug 24, 2026
fd41284
Merge branch 'feat/report-findings-typed-contract' of https://github.…
qwen-code-dev-bot Aug 24, 2026
01e5f2b
fix(review): close report_findings contract gaps from review round 5 …
qwen-code-dev-bot Aug 24, 2026
26033e0
fix(review): implement report_findings replacement semantics and clos…
qwen-code-dev-bot Aug 24, 2026
dec4a7c
Merge branch 'main' into feat/report-findings-typed-contract
wenshao Aug 24, 2026
6e242c3
fix(cli): close findings_list boundary bypass and restore superseded …
qwen-code-dev-bot Aug 24, 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
53 changes: 53 additions & 0 deletions docs/design/report-findings-typed-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Report Findings Typed Contract

## Context

`/review` already canonicalizes its findings as data twice: `qwen review
findings` writes the typed artifact under `.qwen/tmp/`, and Step 8's
`save-artifact` + `record_artifact` publish a durable copy the Web Shell
renders (`CodeReviewArtifactDetail`). But both are files registered after the
fact. Every client rendering the session live — the terminal UI, the Web Shell
transcript, ACP hosts, the daemon TUI — receives only the Markdown
restatement of the same list, and after `--fix` (or a later `fix these
issues`) nothing in-band tells a client which findings are now closed.

## Design

A new core tool, `report_findings`, is the in-band half of the contract: one
call with `{level, findings[]}`, rendered by host UIs as a per-finding list.
Field names and enum spellings match the findings artifact exactly (`id`,
`severity`, `confidence`, `source`, `file`/`line`, `summary`, `shortSummary`,
`failureScenario`, `category`, `outcome`, `outcomeNote`), so the model copies
values out of the artifact instead of translating them. The tool sorts by
severity → confidence → location, derives and compresses `shortSummary` to 60
characters, rejects control characters and duplicate ids, and — mirroring
`review findings --outcomes` — refuses a call where some findings carry an
`outcome` and others do not. It persists nothing and decides no verdict; the
result is a `findings_list` structured `returnDisplay`.

The finding enums now live in core (`tools/report-findings.ts`);
`packages/cli/src/utils/findings.ts` re-exports them under its historical
names. The Web Shell renderer keeps its deliberate browser-side copy.

The `/review` skill calls the tool once after writing the findings artifact
(Step 6; low effort reports its unverified list with `level: "low"`), and
again after `--fix` with every finding carrying its outcome — a rule that
outlives Step 6B: any later in-session disposition change records outcomes
into the artifact and re-issues the call. The call is UI delivery: a failure
is disclosed and never alters artifacts or the verdict.

Rendering: the TUI gets a `FindingsDisplay` row list (severity color, id,
`file:line`, short summary, confidence marker, outcome badge); the daemon TUI
adapter passes `findings_list` through; history/recording compaction truncates
only the free-text fields.

## Verification

- Core tool unit tests: sorting, shortSummary derivation/compression, empty
list, outcome counting, partial-outcome refusal, duplicate ids, control
characters, schema violations, trimming.
- Compaction test: free-text fields truncate, typed fields survive.
- `FindingsDisplay` ink render tests: rows, outcomes with skip reason, empty
state.
- Existing `findings.ts`, `save-artifact`, ToolMessage, daemon adapter,
config-registration, SKILL parity and review-digest suites stay green.
1 change: 1 addition & 0 deletions packages/cli/src/i18n/locales/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,7 @@ export default {
'toolDisplayName.Agent': 'Agent',
'toolDisplayName.Artifact': 'Artefacte',
'toolDisplayName.RecordArtifact': "Enregistra l'artefacte",
'toolDisplayName.ReportFindings': 'Informa de les troballes',
'toolDisplayName.Skill': 'Habilitat',
'toolDisplayName.EnterPlanMode': 'Entra al mode de planificació',
'toolDisplayName.ExitPlanMode': 'Surt del mode de planificació',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export default {
'toolDisplayName.Agent': 'toolDisplayName.Agent',
'toolDisplayName.Artifact': 'toolDisplayName.Artifact',
'toolDisplayName.RecordArtifact': 'toolDisplayName.RecordArtifact',
'toolDisplayName.ReportFindings': 'toolDisplayName.ReportFindings',
'toolDisplayName.DisplayImage': 'toolDisplayName.DisplayImage',
'toolDisplayName.Skill': 'toolDisplayName.Skill',
'toolDisplayName.EnterPlanMode': 'toolDisplayName.EnterPlanMode',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/i18n/locales/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default {
'toolDisplayName.Agent': 'Agent',
'toolDisplayName.Artifact': '製品',
'toolDisplayName.RecordArtifact': '記錄製品',
'toolDisplayName.ReportFindings': '上報評審發現',
'toolDisplayName.DisplayImage': '顯示圖片',
'toolDisplayName.Skill': '技能',
'toolDisplayName.EnterPlanMode': '進入計畫模式',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/i18n/locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default {
'toolDisplayName.Agent': 'Agent',
'toolDisplayName.Artifact': '制品',
'toolDisplayName.RecordArtifact': '记录制品',
'toolDisplayName.ReportFindings': '上报评审发现',
'toolDisplayName.DisplayImage': '显示图片',
'toolDisplayName.Skill': '技能',
'toolDisplayName.EnterPlanMode': '进入计划模式',
Expand Down
78 changes: 78 additions & 0 deletions packages/cli/src/ui/components/FindingsDisplay.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { render } from 'ink-testing-library';
import { describe, expect, it } from 'vitest';
import type { FindingsResultDisplay } from '@qwen-code/qwen-code-core';
import { FindingsDisplay } from './FindingsDisplay.js';

function display(
overrides: Partial<FindingsResultDisplay> = {},
): FindingsResultDisplay {
return {
type: 'findings_list',
level: 'high',
findings: [
{
id: 'R1-1',
severity: 'Critical',
confidence: 'high',
file: 'src/foo.ts',
line: 42,
summary: 'wrong return value on cold cache',
shortSummary: 'wrong return value on cold cache',
Comment thread
wenshao marked this conversation as resolved.
Resolved
failureScenario: 'first call after start returns undefined',
},
{
severity: 'Suggestion',
confidence: 'low',
file: 'src/bar.ts',
summary: 'duplicated helper',
shortSummary: 'duplicated helper',
failureScenario: 'two copies drift',
},
],
...overrides,
};
}

describe('<FindingsDisplay />', () => {
it('renders one row per finding with severity, id, location and label', () => {
const { lastFrame } = render(<FindingsDisplay data={display()} />);
const frame = lastFrame()!;
expect(frame).toContain('Critical');
expect(frame).toContain('R1-1');
expect(frame).toContain('src/foo.ts:42');
expect(frame).toContain('wrong return value on cold cache');
expect(frame).toContain('Suggestion');
expect(frame).toContain('src/bar.ts');
expect(frame).toContain('(low confidence)');
});

it('renders outcomes with the skip reason', () => {
const data = display();
data.findings = data.findings.map((finding, index) =>
index === 0
? { ...finding, outcome: 'fixed' as const }
: {
...finding,
outcome: 'skipped' as const,
outcomeNote: 'fix would change intended behaviour',
},
);
const { lastFrame } = render(<FindingsDisplay data={data} />);
const frame = lastFrame()!.replace(/\s+/g, ' ');
expect(frame).toContain('(fixed)');
expect(frame).toContain('(skipped: fix would change intended behaviour)');
});

it('renders an explicit empty state', () => {
const { lastFrame } = render(
<FindingsDisplay data={display({ findings: [] })} />,
);
expect(lastFrame()).toContain('No findings.');
});
});
103 changes: 103 additions & 0 deletions packages/cli/src/ui/components/FindingsDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import type React from 'react';
import { Box, Text } from 'ink';
import type {
FindingsResultDisplay,
ReportedFinding,
} from '@qwen-code/qwen-code-core';
import { Colors } from '../colors.js';
import { ICON } from '../constants.js';

interface FindingsDisplayProps {
data: FindingsResultDisplay;
}

const SEVERITY_COLORS: Record<ReportedFinding['severity'], () => string> = {
Critical: () => Colors.AccentRed,
Suggestion: () => Colors.AccentYellow,
'Nice to have': () => Colors.Gray,
};

const OUTCOME_LABELS: Record<
NonNullable<ReportedFinding['outcome']>,
string
> = {
fixed: 'fixed',
skipped: 'skipped',
no_change_needed: 'no change needed',
};

export const FindingsDisplay: React.FC<FindingsDisplayProps> = ({ data }) => {
if (data.findings.length === 0) {
return (
<Box>
<Text color={Colors.Gray}>No findings.</Text>
</Box>
);
}

return (
<Box flexDirection="column">
{data.findings.map((finding, index) => (
<FindingRow
key={finding.id ?? `${finding.file}:${finding.line ?? ''}:${index}`}
finding={finding}
/>
))}
</Box>
);
};

const FindingRow: React.FC<{ finding: ReportedFinding }> = ({ finding }) => {
const severityColor = SEVERITY_COLORS[finding.severity]();
const resolved =
finding.outcome === 'fixed' || finding.outcome === 'no_change_needed';
const icon =
finding.outcome === undefined
? ICON.CIRCLE_FILLED
: resolved
? ICON.CHECK
: ICON.CIRCLE_EMPTY;
const where = `${finding.file}${finding.line !== undefined ? `:${finding.line}` : ''}`;

return (
<Box flexDirection="row" minHeight={1}>
<Box width={3} flexShrink={0}>
<Text color={resolved ? Colors.AccentGreen : severityColor}>
{icon}
</Text>
</Box>
<Box flexGrow={1}>
<Text wrap="wrap">
<Text color={severityColor} bold={finding.severity === 'Critical'}>
{finding.severity}
</Text>
<Text color={Colors.Gray}>{finding.id ? ` ${finding.id}` : ''} </Text>
<Text color={Colors.AccentCyan}>{where}</Text>
<Text color={Colors.Foreground} strikethrough={resolved}>
{' '}
{finding.shortSummary}
</Text>
{finding.confidence === 'low' && (
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
<Text color={Colors.Gray}> (low confidence)</Text>
)}
{finding.outcome && (
<Text color={resolved ? Colors.AccentGreen : Colors.AccentYellow}>
{' '}
({OUTCOME_LABELS[finding.outcome]}
{finding.outcome === 'skipped' && finding.outcomeNote
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
? `: ${finding.outcomeNote}`
: ''}
)
</Text>
)}
</Text>
</Box>
</Box>
);
};
43 changes: 43 additions & 0 deletions packages/cli/src/ui/components/messages/ToolMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,49 @@ describe('<ToolMessage />', () => {
expect(output).not.toContain('MockMarkdown:Test result'); // collapsed
});

it('routes a findings_list result to the findings renderer', () => {
// Pins the ToolMessage discriminator itself: FindingsDisplay has its own
// render tests, but without this the routing branch could be removed and
// every test would stay green (the display would fall through to the
// JSON-string path, which never joins file and line as `file:line`).
const { lastFrame } = renderWithContext(
<ToolMessage
{...baseProps}
name="ReportFindings"
resultDisplay={{
type: 'findings_list',
level: 'high',
findings: [
{
id: 'R1-1',
severity: 'Critical',
confidence: 'high',
file: 'src/foo.ts',
line: 42,
summary: 'wrong return value on cold cache',
shortSummary: 'wrong return value on cold cache',
failureScenario: 'first call after start returns undefined',
},
{
severity: 'Suggestion',
confidence: 'low',
file: 'src/bar.ts',
summary: 'duplicated helper',
shortSummary: 'duplicated helper',
failureScenario: 'two copies drift',
},
],
}}
/>,
StreamingState.Idle,
);
const output = lastFrame()!;
expect(output).toContain('src/foo.ts:42');
expect(output).toContain('wrong return value on cold cache');
expect(output).toContain('(low confidence)');
expect(output).not.toContain('"findings"'); // not the JSON fallback
});

it('renders inline images returned by a tool', () => {
const { lastFrame } = renderWithContext(
<ToolMessage
Expand Down
19 changes: 19 additions & 0 deletions packages/cli/src/ui/components/messages/ToolMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { AnsiOutputText, ShellStatsBar } from '../AnsiOutput.js';
import type { ShellStatsBarProps } from '../AnsiOutput.js';
import { MaxSizedBox, MINIMUM_MAX_HEIGHT } from '../shared/MaxSizedBox.js';
import { TodoDisplay } from '../TodoDisplay.js';
import { FindingsDisplay } from '../FindingsDisplay.js';
import type {
TodoResultDisplay,
FindingsResultDisplay,
AgentResultDisplay,
PlanResultDisplay,
AnsiOutput,
Expand Down Expand Up @@ -172,6 +174,7 @@ function sliceTextForMaxHeight(
type DisplayRendererResult =
| { type: 'none' }
| { type: 'todo'; data: TodoResultDisplay }
| { type: 'findings'; data: FindingsResultDisplay }
| { type: 'plan'; data: PlanResultDisplay }
| { type: 'string'; data: string }
| { type: 'diff'; data: { fileDiff: string; fileName: string } }
Expand Down Expand Up @@ -207,6 +210,19 @@ const useResultDisplayRenderer = (
};
}

// Check for FindingsResultDisplay
if (
typeof resultDisplay === 'object' &&
resultDisplay !== null &&
'type' in resultDisplay &&
resultDisplay.type === 'findings_list'
) {
return {
type: 'findings',
data: resultDisplay as FindingsResultDisplay,
};
}

if (
typeof resultDisplay === 'object' &&
resultDisplay !== null &&
Expand Down Expand Up @@ -931,6 +947,9 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
{effectiveDisplayRenderer.type === 'todo' && (
<TodoResultRenderer data={effectiveDisplayRenderer.data} />
)}
{effectiveDisplayRenderer.type === 'findings' && (
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved
<FindingsDisplay data={effectiveDisplayRenderer.data} />
)}
{effectiveDisplayRenderer.type === 'plan' && (
<PlanResultRenderer
data={effectiveDisplayRenderer.data}
Expand Down
Loading
Loading