aireview 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +209 -79
- data/config/defaults.yml +6 -7
- data/lib/aireview/candidate_checker.rb +0 -1
- data/lib/aireview/cli.rb +91 -63
- data/lib/aireview/config.rb +42 -4
- data/lib/aireview/config_fallbacks.rb +8 -11
- data/lib/aireview/config_layers.rb +6 -4
- data/lib/aireview/config_loader.rb +31 -23
- data/lib/aireview/context_budget.rb +6 -2
- data/lib/aireview/context_builder.rb +1 -0
- data/lib/aireview/dry_run_report.rb +3 -0
- data/lib/aireview/github_client.rb +284 -0
- data/lib/aireview/jev_stage.rb +19 -2
- data/lib/aireview/llm_client.rb +8 -9
- data/lib/aireview/llm_router.rb +69 -90
- data/lib/aireview/model_candidate.rb +6 -3
- data/lib/aireview/model_pool.rb +6 -0
- data/lib/aireview/model_state.rb +5 -17
- data/lib/aireview/mr_parser.rb +44 -6
- data/lib/aireview/platform.rb +99 -0
- data/lib/aireview/publisher.rb +8 -7
- data/lib/aireview/review_comment_formatter.rb +158 -0
- data/lib/aireview/review_marker.rb +5 -1
- data/lib/aireview/review_pipeline.rb +24 -13
- data/lib/aireview/review_renderer.rb +33 -12
- data/lib/aireview/reviewer.rb +4 -5
- data/lib/aireview/stage_chains.rb +4 -0
- data/lib/aireview/version.rb +1 -1
- data/lib/aireview.rb +2 -1
- metadata +13 -14
data/lib/aireview/model_state.rb
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require 'set'
|
|
3
2
|
|
|
4
3
|
module Aireview
|
|
5
4
|
# What the router learned about a model during the run. Three things with
|
|
6
5
|
# different lifetimes: sent requests are counted per stage, a quarantine
|
|
7
6
|
# lasts until a moment in time, an exclusion lasts until the end of the
|
|
8
|
-
# run (the provider has no such model,
|
|
9
|
-
# end of the stage (an invalid result).
|
|
10
|
-
# are remembered separately: a quota is a property of "key + model", a
|
|
11
|
-
# quarantine a property of the model.
|
|
7
|
+
# run (the provider has no such model, daily quota is exhausted) or the
|
|
8
|
+
# end of the stage (an invalid result).
|
|
12
9
|
class ModelState
|
|
13
10
|
# Every request sent, the short retry and the JSON repair included,
|
|
14
|
-
# spends an attempt regardless of its outcome;
|
|
15
|
-
#
|
|
11
|
+
# spends an attempt regardless of its outcome; a quarantine does not
|
|
12
|
+
# reset it.
|
|
16
13
|
MAX_REQUESTS_PER_STAGE = 3
|
|
17
14
|
|
|
18
15
|
attr_reader :excluded_reason
|
|
@@ -23,7 +20,6 @@ module Aireview
|
|
|
23
20
|
@quarantined_until = nil
|
|
24
21
|
@excluded_reason = nil
|
|
25
22
|
@stage_exclusions = {}
|
|
26
|
-
@exhausted_keys = Set.new
|
|
27
23
|
end
|
|
28
24
|
|
|
29
25
|
def sent(stage)
|
|
@@ -42,7 +38,7 @@ module Aireview
|
|
|
42
38
|
@quarantined_until = until_time
|
|
43
39
|
end
|
|
44
40
|
|
|
45
|
-
# A model that answered is not overloaded
|
|
41
|
+
# A model that answered is not overloaded.
|
|
46
42
|
def lift_quarantine
|
|
47
43
|
@quarantined_until = nil
|
|
48
44
|
end
|
|
@@ -61,14 +57,6 @@ module Aireview
|
|
|
61
57
|
@stage_exclusions[stage.to_s] = reason
|
|
62
58
|
end
|
|
63
59
|
|
|
64
|
-
def exhaust_key(key_index)
|
|
65
|
-
@exhausted_keys << key_index
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def key_exhausted?(key_index)
|
|
69
|
-
@exhausted_keys.include?(key_index)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
60
|
# Why the model cannot be tried in the stage; nil — it can (the
|
|
73
61
|
# quarantine is checked separately: it is a wait, not a ban).
|
|
74
62
|
def skip_reason(stage)
|
data/lib/aireview/mr_parser.rb
CHANGED
|
@@ -3,28 +3,66 @@ require 'uri'
|
|
|
3
3
|
|
|
4
4
|
module Aireview
|
|
5
5
|
class MrParser
|
|
6
|
-
Result = Struct.new(:url, :base_url, :project_path, :project_id, :iid, keyword_init: true)
|
|
6
|
+
Result = Struct.new(:platform, :url, :base_url, :project_path, :project_id, :iid, keyword_init: true)
|
|
7
7
|
|
|
8
8
|
MR_PATH = %r{\A/(?<project>.+)/-/merge_requests/(?<iid>\d+)\z}
|
|
9
|
+
# github.com and GitHub Enterprise share the path; the PR page tabs and a
|
|
10
|
+
# trailing slash point at the same pull request.
|
|
11
|
+
PR_PATH = %r{\A/(?<owner>[^/]+)/(?<repo>[^/]+)/pull/(?<number>\d+)(?:/(?:files|commits|checks))?/?\z}
|
|
12
|
+
# What GitHub allows in owner and repository names. Checked here, so that
|
|
13
|
+
# the "owner/repo" id goes into API paths as is, and a malformed URL
|
|
14
|
+
# fails as a URL error instead of a 404.
|
|
15
|
+
GITHUB_NAME = /\A[A-Za-z0-9_.-]+\z/
|
|
9
16
|
|
|
10
17
|
def self.parse(url)
|
|
11
18
|
uri = URI.parse(url.to_s)
|
|
12
19
|
raise ParseError, 'Merge request URL must include http:// or https://' unless uri.is_a?(URI::HTTP)
|
|
13
20
|
|
|
21
|
+
gitlab(url, uri) || github(url, uri) || raise(ParseError, "Unsupported merge request URL: #{url}")
|
|
22
|
+
rescue URI::InvalidURIError => e
|
|
23
|
+
raise ParseError, "Invalid merge request URL: #{e.message}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.gitlab(url, uri)
|
|
14
27
|
match = MR_PATH.match(uri.path)
|
|
15
|
-
|
|
28
|
+
return unless match
|
|
16
29
|
|
|
17
30
|
project_path = match[:project]
|
|
18
|
-
|
|
19
31
|
Result.new(
|
|
32
|
+
platform: :gitlab,
|
|
20
33
|
url: url,
|
|
21
|
-
base_url:
|
|
34
|
+
base_url: base_url(uri),
|
|
22
35
|
project_path: project_path,
|
|
23
36
|
project_id: URI.encode_www_form_component(project_path),
|
|
24
37
|
iid: match[:iid].to_i
|
|
25
38
|
)
|
|
26
|
-
rescue URI::InvalidURIError => e
|
|
27
|
-
raise ParseError, "Invalid merge request URL: #{e.message}"
|
|
28
39
|
end
|
|
40
|
+
|
|
41
|
+
# GitHub takes the repository as two path segments (repos/owner/repo),
|
|
42
|
+
# not one encoded segment like a GitLab project id.
|
|
43
|
+
def self.github(url, uri)
|
|
44
|
+
match = PR_PATH.match(uri.path)
|
|
45
|
+
return unless match
|
|
46
|
+
|
|
47
|
+
owner, repo = match.values_at(:owner, :repo)
|
|
48
|
+
unless [owner, repo].all? { |name| GITHUB_NAME.match?(name) }
|
|
49
|
+
raise ParseError, "Unsupported pull request URL: #{url}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
Result.new(
|
|
53
|
+
platform: :github,
|
|
54
|
+
url: url,
|
|
55
|
+
base_url: base_url(uri),
|
|
56
|
+
project_path: "#{owner}/#{repo}",
|
|
57
|
+
project_id: "#{owner}/#{repo}",
|
|
58
|
+
iid: match[:number].to_i
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.base_url(uri)
|
|
63
|
+
"#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port && ![80, 443].include?(uri.port)}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private_class_method :gitlab, :github, :base_url
|
|
29
67
|
end
|
|
30
68
|
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'errors'
|
|
3
|
+
require_relative 'utils'
|
|
4
|
+
require_relative 'gitlab_client'
|
|
5
|
+
require_relative 'github_client'
|
|
6
|
+
|
|
7
|
+
module Aireview
|
|
8
|
+
# The only place that knows which platform a review target belongs to:
|
|
9
|
+
# which client to build, how to tell a CI retry from a new push and how to
|
|
10
|
+
# name the target in messages. No requests and no response handling here —
|
|
11
|
+
# those live in the clients.
|
|
12
|
+
module Platform
|
|
13
|
+
PLATFORMS = %i[gitlab github].freeze
|
|
14
|
+
|
|
15
|
+
module_function
|
|
16
|
+
|
|
17
|
+
def client(config:, target:, logger:)
|
|
18
|
+
case platform(target)
|
|
19
|
+
when :gitlab
|
|
20
|
+
GitlabClient.new(
|
|
21
|
+
base_url: config.gitlab_url || target.base_url,
|
|
22
|
+
token: config.require_gitlab_token!,
|
|
23
|
+
logger: logger
|
|
24
|
+
)
|
|
25
|
+
when :github
|
|
26
|
+
GithubClient.new(
|
|
27
|
+
api_url: config.github_api_url || GithubClient.api_url_for(target.base_url),
|
|
28
|
+
token: config.require_github_token!,
|
|
29
|
+
review_author: config.github_review_author,
|
|
30
|
+
logger: logger
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# A Retry of the GitLab job, not a new pipeline: see
|
|
36
|
+
# GitlabClient#retried_job?. GitHub numbers the attempts of a workflow
|
|
37
|
+
# run itself: "Re-run jobs" makes attempt 2. Outside CI nothing is a retry.
|
|
38
|
+
def retried_run?(client:, target:, env:)
|
|
39
|
+
case platform(target)
|
|
40
|
+
when :gitlab
|
|
41
|
+
project_id, job_id = gitlab_job(env)
|
|
42
|
+
project_id ? client.retried_job?(project_id, job_id) : false
|
|
43
|
+
when :github
|
|
44
|
+
github_actions?(env) && env['GITHUB_RUN_ATTEMPT'].to_i > 1
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def update_hint(target:, env:)
|
|
49
|
+
case platform(target)
|
|
50
|
+
when :gitlab
|
|
51
|
+
gitlab_job(env) ? 'retry the job to update' : 'use --force to review again'
|
|
52
|
+
when :github
|
|
53
|
+
github_actions?(env) ? 're-run the workflow to update' : 'use --force to review again'
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def label(target)
|
|
58
|
+
case platform(target)
|
|
59
|
+
when :gitlab then "MR #{target.project_path}!#{target.iid}"
|
|
60
|
+
when :github then "PR #{target.project_path}##{target.iid}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def name(target)
|
|
65
|
+
case platform(target)
|
|
66
|
+
when :gitlab then 'GitLab'
|
|
67
|
+
when :github then 'GitHub'
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def noun(target)
|
|
72
|
+
case platform(target)
|
|
73
|
+
when :gitlab then 'merge request'
|
|
74
|
+
when :github then 'pull request'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def platform(target)
|
|
79
|
+
platform = target.platform
|
|
80
|
+
raise ArgumentError, "Unsupported platform: #{platform.inspect}" unless PLATFORMS.include?(platform)
|
|
81
|
+
|
|
82
|
+
platform
|
|
83
|
+
end
|
|
84
|
+
private_class_method :platform
|
|
85
|
+
|
|
86
|
+
def gitlab_job(env)
|
|
87
|
+
project_id, job_id = env.values_at('CI_PROJECT_ID', 'CI_JOB_ID')
|
|
88
|
+
return if Aireview::Utils.blank?(project_id) || Aireview::Utils.blank?(job_id)
|
|
89
|
+
|
|
90
|
+
[project_id, job_id]
|
|
91
|
+
end
|
|
92
|
+
private_class_method :gitlab_job
|
|
93
|
+
|
|
94
|
+
def github_actions?(env)
|
|
95
|
+
env['GITHUB_ACTIONS'] == 'true'
|
|
96
|
+
end
|
|
97
|
+
private_class_method :github_actions?
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/aireview/publisher.rb
CHANGED
|
@@ -5,8 +5,9 @@ module Aireview
|
|
|
5
5
|
class Publisher
|
|
6
6
|
PREFIX = '**aireview review**'
|
|
7
7
|
|
|
8
|
-
def initialize(
|
|
9
|
-
@
|
|
8
|
+
def initialize(client:, platform_name: 'GitLab', logger: Logger.new($stderr))
|
|
9
|
+
@client = client
|
|
10
|
+
@platform_name = platform_name
|
|
10
11
|
@logger = logger
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -17,7 +18,7 @@ module Aireview
|
|
|
17
18
|
author_id = current_user_id
|
|
18
19
|
legacy = nil
|
|
19
20
|
|
|
20
|
-
@
|
|
21
|
+
@client.fetch_merge_request_notes(project_id, iid).each do |note|
|
|
21
22
|
next if note['system']
|
|
22
23
|
next if note.dig('author', 'id') != author_id
|
|
23
24
|
|
|
@@ -35,9 +36,9 @@ module Aireview
|
|
|
35
36
|
|
|
36
37
|
if existing
|
|
37
38
|
@logger.info("Updating review note #{existing[:id]}")
|
|
38
|
-
@
|
|
39
|
+
@client.update_merge_request_note(project_id, iid, existing[:id], body)
|
|
39
40
|
else
|
|
40
|
-
@
|
|
41
|
+
@client.post_merge_request_note(project_id, iid, body)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -55,8 +56,8 @@ module Aireview
|
|
|
55
56
|
def current_user_id
|
|
56
57
|
return @current_user_id if defined?(@current_user_id)
|
|
57
58
|
|
|
58
|
-
id = @
|
|
59
|
-
raise ApiError,
|
|
59
|
+
id = @client.fetch_current_user['id']
|
|
60
|
+
raise ApiError, "#{@platform_name} did not return the current user id" if Aireview::Utils.blank?(id)
|
|
60
61
|
|
|
61
62
|
@current_user_id = id
|
|
62
63
|
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aireview
|
|
4
|
+
# Shortens rendered review comments to fit a platform character limit
|
|
5
|
+
# without dropping findings or the overall result section.
|
|
6
|
+
class ReviewCommentFormatter
|
|
7
|
+
RESULT_HEADING = /\n## (?:Result|Результат)\n\n/
|
|
8
|
+
NOT_REVIEWED_HEADING = /(\n## (?:Not reviewed|Не вошло в ревью)\n\n)(.*)/m
|
|
9
|
+
SUMMARY_HEADING = /(?:\A|\n)## (?:Summary|Сводка)\n\n/
|
|
10
|
+
|
|
11
|
+
def self.fit(body, limit:)
|
|
12
|
+
new(limit: limit).fit(body)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize(limit:)
|
|
16
|
+
@limit = limit
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def fit(body)
|
|
20
|
+
return body if body.length <= @limit
|
|
21
|
+
|
|
22
|
+
fitted = truncate_not_reviewed(body)
|
|
23
|
+
return fitted if fitted && fitted.length <= @limit
|
|
24
|
+
|
|
25
|
+
fitted = truncate_summary(fitted || body)
|
|
26
|
+
return fitted if fitted && fitted.length <= @limit
|
|
27
|
+
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def truncate_not_reviewed(body)
|
|
34
|
+
result_index = body.rindex(RESULT_HEADING)
|
|
35
|
+
return nil unless result_index
|
|
36
|
+
|
|
37
|
+
match = body[result_index..].match(NOT_REVIEWED_HEADING)
|
|
38
|
+
return nil unless match
|
|
39
|
+
|
|
40
|
+
prefix = body[0...(result_index + match.begin(0))] + match[1]
|
|
41
|
+
is_ru = body.include?('Не вошло в ревью')
|
|
42
|
+
items, footer = split_items_and_footer(match[2])
|
|
43
|
+
|
|
44
|
+
kept, omitted = fit_items(items, prefix: prefix, footer: footer, is_ru: is_ru)
|
|
45
|
+
result_items = kept
|
|
46
|
+
result_items << omission_note(omitted, is_ru) if omitted.positive?
|
|
47
|
+
|
|
48
|
+
"#{prefix}#{result_items.join}#{footer}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def truncate_summary(body)
|
|
52
|
+
prefix, summary, suffix = split_summary_section(body)
|
|
53
|
+
return nil unless prefix
|
|
54
|
+
|
|
55
|
+
is_ru = body.include?('## Сводка')
|
|
56
|
+
note = is_ru ? "\n[сводка усечена]" : "\n[summary truncated]"
|
|
57
|
+
|
|
58
|
+
room = @limit - prefix.length - suffix.length - note.length
|
|
59
|
+
return nil if room.negative?
|
|
60
|
+
|
|
61
|
+
truncated = truncate_with_closed_fence(summary, room)
|
|
62
|
+
|
|
63
|
+
"#{prefix}#{truncated}#{note}#{suffix}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def split_summary_section(body)
|
|
67
|
+
match = body.match(SUMMARY_HEADING)
|
|
68
|
+
return nil unless match
|
|
69
|
+
|
|
70
|
+
prefix = body[0...match.end(0)]
|
|
71
|
+
rest = body[match.end(0)..]
|
|
72
|
+
boundary = find_next_heading_offset(rest)
|
|
73
|
+
return nil unless boundary
|
|
74
|
+
|
|
75
|
+
[prefix, rest[0...(boundary - 2)], rest[(boundary - 2)..]]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def find_next_heading_offset(rest)
|
|
79
|
+
fence = nil
|
|
80
|
+
prev_blank = false
|
|
81
|
+
offset = 0
|
|
82
|
+
rest.each_line do |line|
|
|
83
|
+
return offset if fence.nil? && prev_blank && line.start_with?('## ')
|
|
84
|
+
|
|
85
|
+
fence = next_fence_state(line, fence)
|
|
86
|
+
prev_blank = (line == "\n")
|
|
87
|
+
offset += line.length
|
|
88
|
+
end
|
|
89
|
+
nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def truncate_with_closed_fence(summary, room)
|
|
93
|
+
loop do
|
|
94
|
+
truncated = summary[0, room]
|
|
95
|
+
fence = open_fence(truncated)
|
|
96
|
+
return truncated unless fence
|
|
97
|
+
|
|
98
|
+
closing = "\n#{fence}"
|
|
99
|
+
return '' if room < closing.length
|
|
100
|
+
|
|
101
|
+
candidate = summary[0, room - closing.length]
|
|
102
|
+
return "#{candidate}#{closing}" if open_fence(candidate) == fence
|
|
103
|
+
|
|
104
|
+
room -= closing.length
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def open_fence(text)
|
|
109
|
+
fence = nil
|
|
110
|
+
text.each_line { |line| fence = next_fence_state(line, fence) }
|
|
111
|
+
fence
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def next_fence_state(line, fence)
|
|
115
|
+
if fence.nil?
|
|
116
|
+
match = line.match(/^ {0,3}(`{3,}|~{3,})/)
|
|
117
|
+
return match[1] if match
|
|
118
|
+
elsif line.match?(/^ {0,3}#{Regexp.escape(fence[0])}{#{fence.length},}[ \t]*\r?\n?\z/)
|
|
119
|
+
return nil
|
|
120
|
+
end
|
|
121
|
+
fence
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def split_items_and_footer(rest)
|
|
125
|
+
items = []
|
|
126
|
+
trailer = []
|
|
127
|
+
in_items = true
|
|
128
|
+
rest.lines.each do |line|
|
|
129
|
+
if in_items && line.start_with?('- ')
|
|
130
|
+
items << line
|
|
131
|
+
else
|
|
132
|
+
in_items = false
|
|
133
|
+
trailer << line
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
[items, trailer.join]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def fit_items(items, prefix:, footer:, is_ru:)
|
|
140
|
+
kept = []
|
|
141
|
+
kept_length = 0
|
|
142
|
+
items.each_with_index do |line, index|
|
|
143
|
+
remaining = items.size - (index + 1)
|
|
144
|
+
omission = remaining.positive? ? omission_note(remaining, is_ru) : ''
|
|
145
|
+
candidate_size = prefix.length + kept_length + line.length + omission.length + footer.length
|
|
146
|
+
break if candidate_size > @limit
|
|
147
|
+
|
|
148
|
+
kept << line
|
|
149
|
+
kept_length += line.length
|
|
150
|
+
end
|
|
151
|
+
[kept, items.size - kept.size]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def omission_note(count, is_ru)
|
|
155
|
+
is_ru ? "- ... и ещё #{count} файлов не показано\n" : "- ... and #{count} more files not shown\n"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -27,7 +27,9 @@ module Aireview
|
|
|
27
27
|
# Config#result_signature. Without a pool the key is the same as before.
|
|
28
28
|
# The LLM Critique counts only when it can run (its prompt is there),
|
|
29
29
|
# Jev only when it decides (its question templates are there): with the
|
|
30
|
-
# default engine the key is what it was before Jev.
|
|
30
|
+
# default engine the key is what it was before Jev. Files the platform did
|
|
31
|
+
# not return never reach the prompts, yet the report counts them: a
|
|
32
|
+
# nonzero count enters the key, zero leaves it as before.
|
|
31
33
|
def key(prompts:, config:)
|
|
32
34
|
signature = config.result_signature
|
|
33
35
|
source = {
|
|
@@ -37,6 +39,8 @@ module Aireview
|
|
|
37
39
|
jev = prompts[:jev_questions]
|
|
38
40
|
source['critique_engine'] = [*signature['critique_engine'], jev] if jev
|
|
39
41
|
source['pool'] = signature['pool'] if signature['pool']
|
|
42
|
+
missing = prompts[:coverage]&.files_not_returned.to_i
|
|
43
|
+
source['files_not_returned'] = missing if missing.positive?
|
|
40
44
|
|
|
41
45
|
Digest::SHA256.hexdigest(JSON.generate(source))[0, 16]
|
|
42
46
|
end
|
|
@@ -69,11 +69,11 @@ module Aireview
|
|
|
69
69
|
"(model=#{@reviewer.answered_model('generate')})")
|
|
70
70
|
candidates = check_candidates(context: context, changes: changes, candidates: candidates)
|
|
71
71
|
|
|
72
|
-
accepted, jev_note = if critique
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
accepted, jev_note, critique_model = if critique
|
|
73
|
+
maybe_critique(context: context, candidates: candidates)
|
|
74
|
+
else
|
|
75
|
+
skip_critique(candidates, status: :critique_disabled)
|
|
76
|
+
end
|
|
77
77
|
|
|
78
78
|
@logger.info("Pipeline finished with #{accepted.size} accepted finding(s)")
|
|
79
79
|
|
|
@@ -81,7 +81,7 @@ module Aireview
|
|
|
81
81
|
accepted,
|
|
82
82
|
summary: summary,
|
|
83
83
|
coverage: context.coverage,
|
|
84
|
-
|
|
84
|
+
models: report_models(critique_model),
|
|
85
85
|
critique_weaker: critique && @reviewer.critique_weaker?,
|
|
86
86
|
jev_note: jev_note
|
|
87
87
|
)
|
|
@@ -95,6 +95,12 @@ module Aireview
|
|
|
95
95
|
|
|
96
96
|
private
|
|
97
97
|
|
|
98
|
+
def report_models(critique_model)
|
|
99
|
+
models = @reviewer.models.dup
|
|
100
|
+
models['critique'] = critique_model if critique_model && !models.empty?
|
|
101
|
+
models
|
|
102
|
+
end
|
|
103
|
+
|
|
98
104
|
# A stage is a request, parsing and one repair by the same model. An
|
|
99
105
|
# invalid result after the repair, like a repair with no requests left,
|
|
100
106
|
# excludes the model for the stage, and the stage starts over on the next
|
|
@@ -124,22 +130,22 @@ module Aireview
|
|
|
124
130
|
).check(candidates)
|
|
125
131
|
end
|
|
126
132
|
|
|
127
|
-
# Returns the candidates
|
|
128
|
-
def skip_critique(candidates, reason = nil)
|
|
133
|
+
# Returns the candidates, no report note and the critique status, like every critique path.
|
|
134
|
+
def skip_critique(candidates, reason = nil, status:)
|
|
129
135
|
@logger.info(['Pipeline critique pass skipped', reason].compact.join(': '))
|
|
130
|
-
[candidates, nil]
|
|
136
|
+
[candidates, nil, status]
|
|
131
137
|
end
|
|
132
138
|
|
|
133
139
|
# Critique has nothing to filter without candidates: the LLM request
|
|
134
|
-
# would waste quota and time. Returns [accepted, note for the report].
|
|
140
|
+
# would waste quota and time. Returns [accepted, note for the report, critique model/status].
|
|
135
141
|
def maybe_critique(context:, candidates:)
|
|
136
|
-
return skip_critique(candidates, 'no candidates') if candidates.empty?
|
|
142
|
+
return skip_critique(candidates, 'no candidates', status: :critique_no_candidates) if candidates.empty?
|
|
137
143
|
return jev_critique(context: context, candidates: candidates) if @config.jev_critique?
|
|
138
144
|
|
|
139
145
|
@logger.info("Pipeline critique pass started (model=#{@config.critique_model})")
|
|
140
146
|
accepted = critique_candidates(context: context, candidates: candidates)
|
|
141
147
|
@jev_shadow.run(context: context, candidates: candidates, accepted: accepted) if @config.jev_shadow?
|
|
142
|
-
[accepted, nil]
|
|
148
|
+
[accepted, nil, @reviewer.models['critique']]
|
|
143
149
|
end
|
|
144
150
|
|
|
145
151
|
def jev_critique(context:, candidates:)
|
|
@@ -149,7 +155,12 @@ module Aireview
|
|
|
149
155
|
)
|
|
150
156
|
llm_critique = ->(subset) { critique_candidates(context: context, candidates: subset) }
|
|
151
157
|
outcome = @jev_stage.run(context: context, candidates: candidates, llm_critique: llm_critique)
|
|
152
|
-
|
|
158
|
+
critique_model = if outcome.model.is_a?(Symbol)
|
|
159
|
+
outcome.model
|
|
160
|
+
else
|
|
161
|
+
Aireview::Utils.presence([outcome.model, @reviewer.models['critique']].compact.join(' + '))
|
|
162
|
+
end
|
|
163
|
+
[outcome.accepted, outcome.note, critique_model]
|
|
153
164
|
end
|
|
154
165
|
|
|
155
166
|
def critique_candidates(context:, candidates:)
|
|
@@ -41,11 +41,15 @@ module Aireview
|
|
|
41
41
|
files_not_shown: 'files not reviewed',
|
|
42
42
|
files_partial: 'files reviewed partially',
|
|
43
43
|
files_unavailable: 'files without an available diff',
|
|
44
|
+
files_not_returned: 'files not returned by the platform',
|
|
44
45
|
sections_truncated: 'sections truncated',
|
|
45
46
|
hunks_of: 'hunks shown',
|
|
46
47
|
diff_unavailable: 'diff not available',
|
|
47
48
|
section_list: 'Truncated sections',
|
|
48
|
-
|
|
49
|
+
models_used: 'Models',
|
|
50
|
+
critique_no_candidates: 'skipped (no candidates)',
|
|
51
|
+
critique_no_verdicts: 'skipped (no verdicts)',
|
|
52
|
+
critique_disabled: 'disabled',
|
|
49
53
|
critique_weaker: 'Critique ran on a model weaker than Generate: the findings were checked less strictly.',
|
|
50
54
|
jev: 'The findings were checked by Jev, a fast classifier, without refining their wording.',
|
|
51
55
|
jev_partial: 'The findings were checked by Jev, a fast classifier, without refining their wording; ' \
|
|
@@ -72,11 +76,15 @@ module Aireview
|
|
|
72
76
|
files_not_shown: 'файлов не проверено',
|
|
73
77
|
files_partial: 'файлов проверено частично',
|
|
74
78
|
files_unavailable: 'файлов без доступного диффа',
|
|
79
|
+
files_not_returned: 'файлов не отдано платформой',
|
|
75
80
|
sections_truncated: 'секций усечено',
|
|
76
81
|
hunks_of: 'хунков показано',
|
|
77
82
|
diff_unavailable: 'дифф недоступен',
|
|
78
83
|
section_list: 'Усечённые секции',
|
|
79
|
-
|
|
84
|
+
models_used: 'Модели',
|
|
85
|
+
critique_no_candidates: 'пропущена (нет замечаний)',
|
|
86
|
+
critique_no_verdicts: 'пропущена (нет вердиктов)',
|
|
87
|
+
critique_disabled: 'отключена',
|
|
80
88
|
critique_weaker: 'Критика выполнена моделью слабее generate: замечания проверены менее строго.',
|
|
81
89
|
jev: 'Замечания проверены быстрым классификатором Jev, без уточнения формулировок.',
|
|
82
90
|
jev_partial: 'Замечания проверены быстрым классификатором Jev, без уточнения формулировок; ' \
|
|
@@ -96,7 +104,8 @@ module Aireview
|
|
|
96
104
|
# checked".
|
|
97
105
|
# jev_note — how Jev took part in the critique (see JevStage::Outcome).
|
|
98
106
|
# The facts about the run are named one by one on purpose.
|
|
99
|
-
def render(accepted, summary:, coverage: nil,
|
|
107
|
+
def render(accepted, summary:, coverage: nil, models: {}, # rubocop:disable Metrics/ParameterLists
|
|
108
|
+
critique_weaker: false, jev_note: nil)
|
|
100
109
|
mismatches, important = select_findings(Array(accepted))
|
|
101
110
|
result = mismatches.empty? && important.empty? ? 'ok' : 'needs attention'
|
|
102
111
|
|
|
@@ -116,7 +125,7 @@ module Aireview
|
|
|
116
125
|
## #{label(:result)}
|
|
117
126
|
|
|
118
127
|
#{result}#{partial_note(coverage)}
|
|
119
|
-
#{coverage_block(coverage)}#{
|
|
128
|
+
#{coverage_block(coverage)}#{models_note(models)}#{weaker_note(critique_weaker)}#{jev_note(jev_note)}
|
|
120
129
|
#{label(:disclaimer)}
|
|
121
130
|
MARKDOWN
|
|
122
131
|
end
|
|
@@ -172,6 +181,7 @@ module Aireview
|
|
|
172
181
|
files_not_shown: coverage.files_not_shown.size,
|
|
173
182
|
files_partial: coverage.files_partial.size,
|
|
174
183
|
files_unavailable: coverage.files_unavailable.size,
|
|
184
|
+
files_not_returned: coverage.files_not_returned,
|
|
175
185
|
sections_truncated: coverage.truncated_sections.size
|
|
176
186
|
}.reject { |_, count| count.zero? }.map { |key, count| "#{count} #{label(key)}" }
|
|
177
187
|
|
|
@@ -186,15 +196,23 @@ module Aireview
|
|
|
186
196
|
"- #{file[:path]}: #{file[:shown]}/#{file[:total]} #{label(:hunks_of)}"
|
|
187
197
|
end
|
|
188
198
|
lines += coverage.files_unavailable.map { |path| "- #{path}: #{label(:diff_unavailable)}" }
|
|
199
|
+
lines += summary_lines(coverage)
|
|
200
|
+
|
|
201
|
+
"\n## #{label(:not_reviewed)}\n\n#{lines.join("\n")}\n"
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# What the report can only count or name, not list by file.
|
|
205
|
+
def summary_lines(coverage)
|
|
206
|
+
lines = []
|
|
207
|
+
lines << "- #{coverage.files_not_returned} #{label(:files_not_returned)}" if coverage.files_not_returned.positive?
|
|
189
208
|
unless coverage.truncated_sections.empty?
|
|
190
209
|
lines << "- #{label(:section_list)}: #{coverage.truncated_sections.join(', ')}"
|
|
191
210
|
end
|
|
192
|
-
|
|
193
|
-
"\n## #{label(:not_reviewed)}\n\n#{lines.join("\n")}\n"
|
|
211
|
+
lines
|
|
194
212
|
end
|
|
195
213
|
|
|
196
|
-
# A
|
|
197
|
-
#
|
|
214
|
+
# A model switch is visible to the reader, because a fallback model may
|
|
215
|
+
# review less well than the primary.
|
|
198
216
|
def weaker_note(critique_weaker)
|
|
199
217
|
return '' unless critique_weaker
|
|
200
218
|
|
|
@@ -207,11 +225,14 @@ module Aireview
|
|
|
207
225
|
note ? "\n#{label(note)}\n" : ''
|
|
208
226
|
end
|
|
209
227
|
|
|
210
|
-
def
|
|
211
|
-
return '' if
|
|
228
|
+
def models_note(models)
|
|
229
|
+
return '' if models.nil? || models.empty?
|
|
212
230
|
|
|
213
|
-
used =
|
|
214
|
-
|
|
231
|
+
used = models.map do |stage, model|
|
|
232
|
+
text = model.is_a?(Symbol) ? label(model) : model
|
|
233
|
+
"#{stage} — #{text}"
|
|
234
|
+
end.join(', ')
|
|
235
|
+
"\n#{label(:models_used)}: #{used}.\n"
|
|
215
236
|
end
|
|
216
237
|
|
|
217
238
|
def location(finding)
|
data/lib/aireview/reviewer.rb
CHANGED
|
@@ -33,9 +33,9 @@ module Aireview
|
|
|
33
33
|
call_llm(prompt, pinned: pinned)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# Stages answered by
|
|
37
|
-
def
|
|
38
|
-
@router.
|
|
36
|
+
# Stages answered by any model, for the report line.
|
|
37
|
+
def models
|
|
38
|
+
@router.models
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# The model that answered last in the stage with its place in the chain, for the log.
|
|
@@ -67,8 +67,7 @@ module Aireview
|
|
|
67
67
|
def call_llm(prompt, pinned:)
|
|
68
68
|
@finish_reasons.delete(prompt.stage)
|
|
69
69
|
response = @router.call(stage: prompt.stage, request_chars: prompt.chars, pinned: pinned) do |route, timeout|
|
|
70
|
-
@client.request(prompt, candidate: route.candidate, key: route.key,
|
|
71
|
-
timeout: timeout)
|
|
70
|
+
@client.request(prompt, candidate: route.candidate, key: route.key, timeout: timeout)
|
|
72
71
|
end
|
|
73
72
|
@finish_reasons[prompt.stage] = response.finish_reason
|
|
74
73
|
LlmClient.content(response)
|
data/lib/aireview/version.rb
CHANGED