aireview 2.2.0 → 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.
@@ -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
- maybe_critique(context: context, candidates: candidates)
74
- else
75
- skip_critique(candidates)
76
- end
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
- fallback_models: @reviewer.fallback_models,
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 and no report note, like every critique path.
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
- [outcome.accepted, outcome.note]
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
- fallback_used: 'Fallback model used',
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
- fallback_used: 'Использована резервная модель',
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, fallback_models: {}, critique_weaker: false, jev_note: nil) # rubocop:disable Metrics/ParameterLists
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)}#{fallback_note(fallback_models)}#{weaker_note(critique_weaker)}#{jev_note(jev_note)}
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 key switch stays in the logs; a model switch is visible to the
197
- # reader, because a fallback model may review less well than the primary.
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 fallback_note(fallback_models)
211
- return '' if fallback_models.nil? || fallback_models.empty?
228
+ def models_note(models)
229
+ return '' if models.nil? || models.empty?
212
230
 
213
- used = fallback_models.map { |stage, model| "#{stage} — #{model}" }.join(', ')
214
- "\n#{label(:fallback_used)}: #{used}.\n"
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)
@@ -33,9 +33,9 @@ module Aireview
33
33
  call_llm(prompt, pinned: pinned)
34
34
  end
35
35
 
36
- # Stages answered by a fallback model, for the report line.
37
- def fallback_models
38
- @router.fallback_models
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, key_index: route.key_index,
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)
@@ -85,6 +85,10 @@ module Aireview
85
85
  false
86
86
  end
87
87
 
88
+ def ranked_critique?(_after)
89
+ false
90
+ end
91
+
88
92
  def signature
89
93
  nil
90
94
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Aireview
3
- VERSION = '2.2.0'
3
+ VERSION = '2.3.0'
4
4
  end
data/lib/aireview.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  require 'json'
3
3
  require 'logger'
4
4
  require 'optparse'
5
- require 'pathname'
6
5
  require 'uri'
7
6
  require 'yaml'
8
7
 
@@ -18,6 +17,8 @@ require_relative 'aireview/reviewer'
18
17
  require_relative 'aireview/review_pipeline'
19
18
  require_relative 'aireview/model_checker'
20
19
  require_relative 'aireview/gitlab_client'
20
+ require_relative 'aireview/github_client'
21
+ require_relative 'aireview/platform'
21
22
  require_relative 'aireview/jira_client'
22
23
  require_relative 'aireview/review_marker'
23
24
  require_relative 'aireview/publisher'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aireview
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Levenko
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-09-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: dotenv
@@ -58,12 +57,11 @@ dependencies:
58
57
  - - '='
59
58
  - !ruby/object:Gem::Version
60
59
  version: 2.0.0
61
- description: 'Reviews self-hosted GitLab merge requests with a two-pass LLM pipeline:
62
- the first pass finds candidate findings, the second one critiques them and drops
63
- the weak ones. Supports Gemini, Ollama, OpenAI, Anthropic, OpenRouter and OpenAI-compatible
64
- servers, Jev as the critic, optional Jira context and posting a single updatable
65
- review note back to the merge request.'
66
- email:
60
+ description: 'Reviews GitLab merge requests and GitHub pull requests with a two-pass
61
+ LLM pipeline: the first pass finds candidate findings, the second one critiques
62
+ them and drops the weak ones. Supports Gemini, Ollama, OpenAI, Anthropic, OpenRouter
63
+ and OpenAI-compatible servers, Jev as the critic, optional Jira context and posting
64
+ a single updatable review comment back to the merge or pull request.'
67
65
  executables:
68
66
  - aireview
69
67
  extensions: []
@@ -91,6 +89,7 @@ files:
91
89
  - lib/aireview/dry_run_prompts.rb
92
90
  - lib/aireview/dry_run_report.rb
93
91
  - lib/aireview/errors.rb
92
+ - lib/aireview/github_client.rb
94
93
  - lib/aireview/gitlab_client.rb
95
94
  - lib/aireview/jev_client.rb
96
95
  - lib/aireview/jev_critic.rb
@@ -106,11 +105,13 @@ files:
106
105
  - lib/aireview/model_state.rb
107
106
  - lib/aireview/mr_parser.rb
108
107
  - lib/aireview/output_schemas.rb
108
+ - lib/aireview/platform.rb
109
109
  - lib/aireview/prompts/critique.txt
110
110
  - lib/aireview/prompts/generate.txt
111
111
  - lib/aireview/prompts/jev_questions.yml
112
112
  - lib/aireview/publisher.rb
113
113
  - lib/aireview/result_parser.rb
114
+ - lib/aireview/review_comment_formatter.rb
114
115
  - lib/aireview/review_marker.rb
115
116
  - lib/aireview/review_pipeline.rb
116
117
  - lib/aireview/review_renderer.rb
@@ -131,7 +132,6 @@ metadata:
131
132
  bug_tracker_uri: https://github.com/DenisDenis9331/aireview/issues
132
133
  funding_uri: https://ko-fi.com/denis1011101
133
134
  rubygems_mfa_required: 'true'
134
- post_install_message:
135
135
  rdoc_options: []
136
136
  require_paths:
137
137
  - lib
@@ -139,15 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 3.1.3
142
+ version: 4.0.10
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
- rubygems_version: 3.3.26
150
- signing_key:
149
+ rubygems_version: 4.0.20
151
150
  specification_version: 4
152
- summary: Local GitLab merge request review CLI powered by LLMs
151
+ summary: GitLab merge request and GitHub pull request review CLI powered by LLMs
153
152
  test_files: []