rails-ai-bridge 5.2.1 → 5.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.reek.yml +3 -19
  3. data/Archspec.rb +0 -1
  4. data/CHANGELOG.md +67 -0
  5. data/CONTRIBUTING.md +5 -5
  6. data/README.md +14 -6
  7. data/UPGRADING.md +31 -0
  8. data/docs/GUIDE.md +28 -0
  9. data/docs/ROADMAP.md +3 -3
  10. data/docs/design/prism-confidence-tags.md +40 -21
  11. data/docs/mcp-security.md +3 -2
  12. data/lib/rails_ai_bridge/config/static_analysis.rb +28 -0
  13. data/lib/rails_ai_bridge/configuration.rb +11 -0
  14. data/lib/rails_ai_bridge/introspectors/controller_introspector/filter_extractor.rb +8 -1
  15. data/lib/rails_ai_bridge/introspectors/controller_introspector/strong_params_provenance.rb +41 -0
  16. data/lib/rails_ai_bridge/introspectors/controller_introspector.rb +26 -2
  17. data/lib/rails_ai_bridge/introspectors/static_prism_scanner.rb +134 -0
  18. data/lib/rails_ai_bridge/introspectors/view_introspector.rb +14 -2
  19. data/lib/rails_ai_bridge/mcp/cache_rate_limiter.rb +3 -2
  20. data/lib/rails_ai_bridge/resources.rb +22 -0
  21. data/lib/rails_ai_bridge/rubydex_adapter/incremental_indexer.rb +6 -2
  22. data/lib/rails_ai_bridge/tools/confidence_tag.rb +16 -0
  23. data/lib/rails_ai_bridge/tools/get_controllers.rb +25 -2
  24. data/lib/rails_ai_bridge/tools/get_view/full_formatter.rb +44 -13
  25. data/lib/rails_ai_bridge/tools/provenance_lines.rb +33 -0
  26. data/lib/rails_ai_bridge/version.rb +1 -1
  27. data/server.json +1 -1
  28. metadata +5 -7
  29. data/.reviewer.toml +0 -13
  30. data/.rs-guardignore +0 -26
  31. data/lib/rails_ai_bridge/services/app_introspection_service.rb +0 -72
  32. data/lib/rails_ai_bridge/services/configuration_service.rb +0 -59
  33. data/lib/rails_ai_bridge/services/context_generation_service.rb +0 -71
  34. data/lib/rails_ai_bridge/services/file_management_service.rb +0 -174
@@ -28,7 +28,7 @@ module RailsAiBridge
28
28
  private
29
29
 
30
30
  def build_filter(callback)
31
- filter = { name: callback.filter.to_s, kind: callback.kind.to_s }
31
+ filter = { name: callback.filter.to_s, kind: callback.kind.to_s, provenance: :reflection }
32
32
  source = source_class_name(callback)
33
33
  filter[:source] = source if source
34
34
  append_conditions(filter, callback)
@@ -148,6 +148,13 @@ module RailsAiBridge
148
148
  except = extract_action_conditions(callback.instance_variable_get(:@unless))
149
149
  filter[:only] = only if only.any?
150
150
  filter[:except] = except if except.any?
151
+ filter[:provenance] = :regex if inferred_conditions?(callback)
152
+ end
153
+
154
+ # ActionFilter conditions are reflected. Actions parsed from a string condition's source text are inferred.
155
+ def inferred_conditions?(callback)
156
+ conditions = [callback.instance_variable_get(:@if), callback.instance_variable_get(:@unless)].flatten.compact
157
+ conditions.any? { |condition| !action_filter_actions(condition) && parse_action_condition(condition) }
151
158
  end
152
159
 
153
160
  def extract_action_conditions(conditions)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAiBridge
4
+ module Introspectors
5
+ class ControllerIntrospector
6
+ # Decides how strong-params methods are labelled. Prism confirms a method when its scan
7
+ # finds it as an instance +def+ directly in this controller's class body. The section is
8
+ # +:prism+ only when every method the regex found is confirmed. Otherwise it stays +:regex+,
9
+ # so one unconfirmed method keeps the whole section inferred.
10
+ class StrongParamsProvenance
11
+ # @param scanner [StaticPrismScanner, nil] Prism scanner for this run, or nil when disabled
12
+ # @param path [String, nil] controller source file
13
+ # @param class_name [String, nil] the controller's full class name, such as +Admin::ReportsController+
14
+ def initialize(scanner, path, class_name)
15
+ @scanner = scanner
16
+ @path = path
17
+ @class_name = class_name
18
+ end
19
+
20
+ # @param strong_params [Array<String>] method names the source regex found
21
+ # @return [Symbol] +:prism+ when every name is confirmed, otherwise +:regex+
22
+ def call(strong_params)
23
+ confirmed = confirmed_methods
24
+ return :regex unless confirmed
25
+
26
+ (strong_params - confirmed).empty? ? :prism : :regex
27
+ end
28
+
29
+ private
30
+
31
+ # @return [Array<String>, nil] instance methods Prism finds in this controller's body, or nil when the scan fails
32
+ def confirmed_methods
33
+ return unless @scanner && @path
34
+
35
+ facts = @scanner.facts_for(@path)[:facts]
36
+ facts&.select { |fact| fact[:kind] == :def && fact[:owner] == @class_name }&.pluck(:name)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -61,6 +61,8 @@ module RailsAiBridge
61
61
 
62
62
  def extract_controller_details(ctrl)
63
63
  source = read_source(ctrl)
64
+ strong_params = extract_strong_params(source)
65
+ respond_to_formats = extract_respond_to(source)
64
66
 
65
67
  {
66
68
  parent_class: ctrl.superclass.name,
@@ -68,8 +70,10 @@ module RailsAiBridge
68
70
  actions: extract_actions(ctrl),
69
71
  filters: FilterExtractor.new(ctrl).call,
70
72
  concerns: extract_concerns(ctrl),
71
- strong_params: extract_strong_params(source),
72
- respond_to_formats: extract_respond_to(source)
73
+ strong_params: strong_params,
74
+ strong_params_provenance: strong_params_provenance(ctrl, strong_params),
75
+ respond_to_formats: respond_to_formats,
76
+ respond_to_formats_provenance: (:regex if respond_to_formats.any?)
73
77
  }.compact
74
78
  end
75
79
 
@@ -110,6 +114,26 @@ module RailsAiBridge
110
114
  source.scan(/format\.(\w+)/).flatten.uniq.sort
111
115
  end
112
116
 
117
+ # @return [Symbol, nil] +:prism+ when Prism confirms every strong-params method, +:regex+
118
+ # when it does not, and nil when the controller has no strong-params methods
119
+ def strong_params_provenance(ctrl, strong_params)
120
+ return if strong_params.empty?
121
+
122
+ scanner = prism_scanner
123
+ return :regex unless scanner
124
+
125
+ StrongParamsProvenance.new(scanner, source_path(ctrl), ctrl.name).call(strong_params)
126
+ end
127
+
128
+ # One scanner per run, so +prism_max_files+ caps every controller scanned in that run.
129
+ #
130
+ # @return [StaticPrismScanner, nil] nil unless +prism_enabled+ is on
131
+ def prism_scanner
132
+ return unless config.prism_enabled
133
+
134
+ @prism_scanner ||= StaticPrismScanner.new(max_files: config.prism_max_files)
135
+ end
136
+
113
137
  def read_source(ctrl)
114
138
  path = source_path(ctrl)
115
139
  return nil unless path && File.exist?(path)
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAiBridge
4
+ module Introspectors
5
+ # Optional Prism AST pass that finds controller filter macros and instance method
6
+ # definitions in source files.
7
+ #
8
+ # Facts found this way carry +provenance: :prism+, so the tools layer can
9
+ # render them as +[VERIFIED]+. Prism is not a gem dependency. When it cannot
10
+ # be loaded, or the scan fails, +facts_for+ returns an error hash and never raises.
11
+ class StaticPrismScanner
12
+ # Controller macros whose symbol arguments name filters.
13
+ FILTER_MACROS = %i[
14
+ before_action after_action around_action
15
+ skip_before_action skip_after_action skip_around_action
16
+ ].freeze
17
+
18
+ # Prism node classes, by short name, mapped to the role each plays in the walk. Names are
19
+ # strings so this file does not reference Prism when it loads.
20
+ NODE_ROLES = {
21
+ 'ClassNode' => :class,
22
+ 'ModuleNode' => :module,
23
+ 'SingletonClassNode' => :singleton,
24
+ 'BlockNode' => :block,
25
+ 'DefNode' => :def,
26
+ 'CallNode' => :call
27
+ }.freeze
28
+
29
+ # Scopes whose name becomes part of the owner of the methods inside them.
30
+ NAMESPACE_ROLES = %i[class module].freeze
31
+
32
+ # @param max_files [Integer] maximum number of files this scanner reads
33
+ # @param loader [#call] loads the prism library and raises LoadError when it is unavailable
34
+ def initialize(max_files:, loader: -> { require 'prism' })
35
+ @max_files = max_files
36
+ @files_read = 0
37
+ @prism_available = begin
38
+ loader.call
39
+ true
40
+ rescue LoadError
41
+ false
42
+ end
43
+ end
44
+
45
+ # @param path [String] source file to scan
46
+ # @return [Hash] +{ facts: [...] }+ on success, or +{ error: String }+ when Prism is
47
+ # unavailable, the file limit is reached, or the file cannot be read or parsed
48
+ def facts_for(path)
49
+ blocked_reason = scan_blocked_reason
50
+ return { error: blocked_reason } if blocked_reason
51
+
52
+ scan(path)
53
+ rescue StandardError => error
54
+ { error: "prism scan failed: #{error.message}" }
55
+ end
56
+
57
+ private
58
+
59
+ def scan_blocked_reason
60
+ return 'prism is not available' unless @prism_available
61
+ return "prism_max_files (#{@max_files}) reached" if @files_read >= @max_files
62
+
63
+ nil
64
+ end
65
+
66
+ def scan(path)
67
+ @files_read += 1
68
+ { facts: extract_facts(path) }
69
+ end
70
+
71
+ def extract_facts(path)
72
+ result = Prism.parse(File.read(path))
73
+ raise ArgumentError, 'file has syntax errors' unless result.success?
74
+
75
+ root = result.value
76
+ (filter_facts_in(root) + method_facts(root)).map { |fact| fact.merge(file: path) }
77
+ end
78
+
79
+ # Filter macros in the tree. Method bodies are skipped: a filter macro only registers when
80
+ # it runs in a class or included block.
81
+ def filter_facts_in(root)
82
+ walk(root).select { |node| filter_macro?(node) }.flat_map { |node| filter_facts(node) }
83
+ end
84
+
85
+ # Every node in the tree, depth-first, starting with +node+, without method bodies.
86
+ def walk(node)
87
+ children = node.compact_child_nodes.grep_v(Prism::DefNode)
88
+ [node, *children.flat_map { |child| walk(child) }]
89
+ end
90
+
91
+ # Instance method definitions, each tagged with the class or module that owns it. A
92
+ # method counts only when its direct enclosing scope is a class body, so a same-named
93
+ # method in a nested class, in +class << self+, or in a block is never reported for
94
+ # the outer class.
95
+ def method_facts(node, scope = [])
96
+ role = NODE_ROLES[node.class.name.demodulize]
97
+ return instance_method_facts(node, scope) if role == :def
98
+
99
+ inner = scope + [scope_entry(role, node)].compact
100
+ node.compact_child_nodes.flat_map { |child| method_facts(child, inner) }
101
+ end
102
+
103
+ # The scope a node opens for the definitions inside it, or nil when it opens none.
104
+ # :reek:UtilityFunction -- a pure mapping from the node's role to the scope it opens
105
+ def scope_entry(role, node)
106
+ case role
107
+ when :class, :module then [role, node.constant_path.slice]
108
+ when :singleton, :block then [role, nil]
109
+ end
110
+ end
111
+
112
+ # :reek:FeatureEnvy -- builds the fact from the method node it is given
113
+ # :reek:UtilityFunction -- a pure builder over the node and its scope
114
+ def instance_method_facts(node, scope)
115
+ return [] if node.receiver || scope.last&.first != :class
116
+
117
+ owner = scope.filter_map { |kind, name| name if NAMESPACE_ROLES.include?(kind) }.join('::')
118
+ [{ kind: :def, name: node.name.to_s, owner: owner, line: node.location.start_line, provenance: :prism }]
119
+ end
120
+
121
+ # :reek:UtilityFunction -- a pure predicate on the node; the macro list is a constant
122
+ def filter_macro?(node)
123
+ NODE_ROLES[node.class.name.demodulize] == :call && !node.receiver && FILTER_MACROS.include?(node.name)
124
+ end
125
+
126
+ # :reek:FeatureEnvy -- builds facts from the macro node it is given
127
+ def filter_facts(node)
128
+ Array(node.arguments&.arguments).grep(Prism::SymbolNode).map do |symbol|
129
+ { kind: node.name, name: symbol.unescaped, line: node.location.start_line, provenance: :prism }
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -5,6 +5,17 @@ module RailsAiBridge
5
5
  # Scans view layer: layouts, templates, partials, helpers,
6
6
  # view components, and template engine detection.
7
7
  class ViewIntrospector
8
+ # Evidence origin of each listing. Files found on disk are observed live, helper methods are
9
+ # scanned with a regex, and template engines are inferred from file extensions.
10
+ PROVENANCE = {
11
+ layouts: :live,
12
+ templates: :live,
13
+ partials: :live,
14
+ helpers: :regex,
15
+ view_components: :live,
16
+ template_engines: :heuristic
17
+ }.freeze
18
+
8
19
  attr_reader :app
9
20
 
10
21
  # Accumulates renderable templates grouped by controller directory.
@@ -90,7 +101,7 @@ module RailsAiBridge
90
101
  # components, and template engines discovered through configured Rails
91
102
  # paths.
92
103
  #
93
- # @return [Hash] view-layer metadata, or an +:error+ key when detection fails
104
+ # @return [Hash] view-layer metadata with a +:provenance+ map per listing, or an +:error+ key when detection fails
94
105
  def call
95
106
  {
96
107
  layouts: extract_layouts,
@@ -98,7 +109,8 @@ module RailsAiBridge
98
109
  partials: extract_partials,
99
110
  helpers: extract_helpers,
100
111
  view_components: extract_view_components,
101
- template_engines: detect_template_engines
112
+ template_engines: detect_template_engines,
113
+ provenance: PROVENANCE
102
114
  }
103
115
  rescue StandardError => error
104
116
  { error: error.message }
@@ -12,8 +12,9 @@ module RailsAiBridge
12
12
  # @param max_requests [Integer] allowed hits per window per client IP
13
13
  # @param window_seconds [Integer] TTL for each client's counter
14
14
  # @param cache [Object, nil] +ActiveSupport::Cache::Store+; defaults to +Rails.cache+
15
- # @param key_prefix [String] prefix for cache keys
16
- def initialize(max_requests:, window_seconds:, cache: nil, key_prefix: 'rab:rl')
15
+ # @param key_prefix [String] prefix for cache keys; defaults to +config.mcp.rate_limiter_key_prefix+
16
+ def initialize(max_requests:, window_seconds:, cache: nil,
17
+ key_prefix: RailsAiBridge.configuration.mcp.rate_limiter_key_prefix || 'rab:rl')
17
18
  @max_requests = max_requests
18
19
  @window_seconds = window_seconds.to_i
19
20
  @cache = cache
@@ -6,6 +6,28 @@ require 'mcp'
6
6
  module RailsAiBridge
7
7
  # Registers MCP resources and resource templates that expose
8
8
  # static introspection data AI clients can read directly.
9
+ #
10
+ # == Architectural role: intentional protocol facade
11
+ #
12
+ # Resources is deliberately the single read-side gateway between every
13
+ # data-producing subsystem and the MCP resource surface. Its edges to
14
+ # ContextProvider (cached context), Registry::RegistryManifest (dynamic
15
+ # context-provider resources), Serializers::ContextSummary (sanitization),
16
+ # ViewFileAnalyzer, Server, and Doctor::Checkers::BridgeMetadataChecker
17
+ # exist because MCP requires one registration and dispatch point — the
18
+ # subsystems only meet here.
19
+ #
20
+ # It is NOT a god module despite high betweenness centrality in graph
21
+ # analyses: a protocol boundary that declares URIs, dispatches reads,
22
+ # and sanitizes output is expected to sit between otherwise unrelated
23
+ # communities. Splitting it would scatter URI ownership and the
24
+ # sanitization guard across multiple files.
25
+ #
26
+ # If a future graph analysis flags this module, check the betweenness
27
+ # against the "facade at a protocol boundary" pattern before proposing a
28
+ # split. The one edge to watch instead: sanitize_conventions_section
29
+ # reaches into Serializers::ContextSummary internals; extract a shared
30
+ # sanitizer if serializers are refactored.
9
31
  module Resources
10
32
  # URI pattern for matching model resource URIs (rails://models/{name})
11
33
  MODEL_URI_PATTERN = %r{\Arails://models/(.+)\z}
@@ -39,7 +39,9 @@ module RailsAiBridge
39
39
  # @option options [Boolean] :persist whether to persist mtimes to disk, default +false+
40
40
  # @option options [String, nil] :index_path directory for the mtime JSON file, default +nil+
41
41
  # @return [Service::Result] result with +graph+ and +file_mtimes+ in data
42
- # @raise [StandardError] rescued and returned as failure result
42
+ # @note {ServiceErrors::BaseError} is rescued internally and returned as a failure result with its message.
43
+ # @note Other +StandardError+ subclasses are rescued internally and returned as a failure result.
44
+ # :reek:DuplicateMethodCall -- each rescue builds its own failure message from error.message
43
45
  def call(operation, root:, graph: nil, file_mtimes: {}, **options)
44
46
  threshold = options.fetch(:threshold, 0.3)
45
47
  persist = options.fetch(:persist, false)
@@ -51,8 +53,10 @@ module RailsAiBridge
51
53
  when :reindex
52
54
  reindex(root, graph, file_mtimes, threshold, persist, index_path)
53
55
  else
54
- Service::Result.new(false, errors: ["Unsupported operation: #{operation}"])
56
+ raise ServiceErrors::ValidationError, "Unsupported operation: #{operation}"
55
57
  end
58
+ rescue ServiceErrors::BaseError => error
59
+ Service::Result.new(false, errors: [error.message])
56
60
  rescue StandardError => error
57
61
  log_error(operation, error)
58
62
  logger = defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : nil
@@ -29,6 +29,22 @@ module RailsAiBridge
29
29
  def tagged(text, source)
30
30
  "#{text} #{tag(source)}"
31
31
  end
32
+
33
+ # Summarizes how many facts came from each evidence source.
34
+ #
35
+ # @param counts [Hash] fact count per source, keyed by Symbol or String, in display order
36
+ # @return [String, nil] e.g. +"Verification: [VERIFIED] reflection (3) · [INFERRED] regex (2)"+,
37
+ # or +nil+ when no source has a positive count
38
+ def footer(counts)
39
+ parts = counts.filter_map do |source, count|
40
+ next unless count.to_i.positive?
41
+
42
+ "#{tag(source)} #{source} (#{count})"
43
+ end
44
+ return if parts.empty?
45
+
46
+ "Verification: #{parts.join(' · ')}"
47
+ end
32
48
  end
33
49
  end
34
50
  end
@@ -42,10 +42,16 @@ module RailsAiBridge
42
42
  # @private
43
43
  # Formats +:controllers+ introspection for {GetControllers}.
44
44
  class ResponseFormatter
45
+ # Provenance missing from a payload falls back to the origin of its field: filters come from
46
+ # Rails reflection, strong params come from source regexes.
47
+ FILTER_FALLBACK = :reflection
48
+ STRONG_PARAMS_FALLBACK = :regex
49
+
45
50
  def initialize(controllers, controller:, detail:)
46
51
  @controllers = controllers
47
52
  @controller = controller
48
53
  @detail = detail
54
+ @provenance = ProvenanceLines.new(RailsAiBridge.configuration.confidence_tags_enabled)
49
55
  end
50
56
 
51
57
  def controller_not_found?
@@ -112,9 +118,14 @@ module RailsAiBridge
112
118
  @controllers.keys.sort.each do |name|
113
119
  info = @controllers[name]
114
120
  lines << "## #{name}"
121
+ footer = footer_for(info)
122
+ lines << '' << footer if footer
115
123
  lines << "- Actions: #{info[:actions]&.join(', ')}" if info[:actions]&.any?
116
124
  lines << "- Filters: #{info[:filters].map { |f| format_listed_filter(f) }.join(', ')}" if info[:filters]&.any?
117
- lines << "- Strong params: #{info[:strong_params].join(', ')}" if info[:strong_params]&.any?
125
+ if info[:strong_params]&.any?
126
+ strong_line = "- Strong params: #{info[:strong_params].join(', ')}"
127
+ lines << @provenance.tag(strong_line, info[:strong_params_provenance] || STRONG_PARAMS_FALLBACK)
128
+ end
118
129
  lines << ''
119
130
  end
120
131
  lines.join("\n")
@@ -142,10 +153,21 @@ module RailsAiBridge
142
153
  "#{label} (#{filter[:source]})"
143
154
  end
144
155
 
156
+ # Summary line counting the filters and strong params this controller renders by provenance.
157
+ # @param info [Hash] one controller's introspection payload
158
+ # @return [String, nil] the footer, or +nil+ when tags are disabled or nothing is counted
159
+ def footer_for(info)
160
+ provenances = Array(info[:filters]).pluck(:provenance).map { |source| source || FILTER_FALLBACK }
161
+ provenances += [info[:strong_params_provenance] || STRONG_PARAMS_FALLBACK] * Array(info[:strong_params]).size
162
+ @provenance.footer(provenances)
163
+ end
164
+
145
165
  def format_single_controller
146
166
  lines = ["# #{controller_key}", '']
147
167
  lines << "**Parent:** `#{controller_info[:parent_class]}`" if controller_info[:parent_class]
148
168
  lines << '**API controller:** yes' if controller_info[:api_controller]
169
+ footer = footer_for(controller_info)
170
+ lines << '' << footer if footer
149
171
 
150
172
  if controller_info[:actions]&.any?
151
173
  lines << '' << '## Actions'
@@ -161,7 +183,8 @@ module RailsAiBridge
161
183
 
162
184
  if controller_info[:strong_params]&.any?
163
185
  lines << '' << '## Strong Params'
164
- lines << controller_info[:strong_params].map { |p| "- `#{p}`" }.join("\n")
186
+ provenance = controller_info[:strong_params_provenance] || STRONG_PARAMS_FALLBACK
187
+ lines << controller_info[:strong_params].map { |p| @provenance.tag("- `#{p}`", provenance) }.join("\n")
165
188
  end
166
189
 
167
190
  lines.join("\n")
@@ -7,25 +7,56 @@ module RailsAiBridge
7
7
  class FullFormatter < BaseFormatter
8
8
  # @return [String] The formatted full output.
9
9
  def call
10
- filtered = filter_view_data
11
- return "View introspection failed: #{filtered[:error]}" if filtered[:error]
10
+ @filtered = filter_view_data
11
+ return "View introspection failed: #{@filtered[:error]}" if @filtered[:error]
12
12
 
13
13
  lines = [StandardFormatter.new(context: @context, controller: @controller, partial: @partial).call]
14
+ lines.concat(helper_lines)
15
+ lines.concat(component_lines)
16
+ footer = tags.footer(fact_provenances)
17
+ lines << '' << footer if footer
18
+ lines.join("\n")
19
+ end
14
20
 
15
- if filtered[:helpers].any?
16
- lines << '' << '## Helpers'
17
- filtered[:helpers].each do |helper|
18
- methods = Array(helper[:methods]).join(', ')
19
- lines << "- `#{helper[:file]}`: #{methods}"
20
- end
21
- end
21
+ private
22
+
23
+ def tags
24
+ @tags ||= ProvenanceLines.new(RailsAiBridge.configuration.confidence_tags_enabled)
25
+ end
26
+
27
+ def section_provenance(section)
28
+ @context.dig(:provenance, section)
29
+ end
22
30
 
23
- if filtered[:view_components].any?
24
- lines << '' << '## View Components'
25
- filtered[:view_components].each { |component| lines << "- `#{component}`" }
31
+ def helper_lines
32
+ helpers = @filtered[:helpers]
33
+ return [] if helpers.empty?
34
+
35
+ helpers.each_with_object(['', '## Helpers']) do |helper, lines|
36
+ methods = Array(helper[:methods]).join(', ')
37
+ lines << tags.tag("- `#{helper[:file]}`: #{methods}", section_provenance(:helpers))
26
38
  end
39
+ end
27
40
 
28
- lines.join("\n")
41
+ # :reek:FeatureEnvy -- formats the component list from the filtered payload; no other state is involved
42
+ def component_lines
43
+ components = @filtered[:view_components]
44
+ return [] if components.empty?
45
+
46
+ ['', '## View Components', *components.map { |component| "- `#{component}`" }]
47
+ end
48
+
49
+ # One provenance per rendered fact, so the footer tallies what the full view shows.
50
+ def fact_provenances
51
+ counts = {
52
+ layouts: @filtered[:layouts].size,
53
+ templates: @filtered[:templates].values.sum(&:size),
54
+ partials: @filtered[:shared_partials].size + @filtered[:controller_partials].values.sum(&:size),
55
+ helpers: @filtered[:helpers].sum { |helper| Array(helper[:methods]).size },
56
+ view_components: @filtered[:view_components].size,
57
+ template_engines: @filtered[:template_engines].size
58
+ }
59
+ counts.flat_map { |section, count| Array.new(count, section_provenance(section)) }
29
60
  end
30
61
  end
31
62
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAiBridge
4
+ module Tools
5
+ # Renders confidence tags into tool output when +confidence_tags_enabled+ is on.
6
+ #
7
+ # With tags off, every method returns its input unchanged, so tool output stays
8
+ # byte-identical to output rendered before tags existed.
9
+ class ProvenanceLines
10
+ # @param enabled [Boolean] whether tags are rendered
11
+ def initialize(enabled)
12
+ @enabled = enabled
13
+ end
14
+
15
+ # @param text [String] fact line without a tag
16
+ # @param provenance [Symbol, nil] evidence origin of the fact
17
+ # @return [String] +text+ with a trailing tag when enabled
18
+ def tag(text, provenance)
19
+ return text unless @enabled
20
+
21
+ ConfidenceTag.tagged(text, provenance)
22
+ end
23
+
24
+ # @param provenances [Array<Symbol, nil>] provenance of each rendered fact
25
+ # @return [String, nil] verification summary line, or +nil+ when disabled or empty
26
+ def footer(provenances)
27
+ return unless @enabled
28
+
29
+ ConfidenceTag.footer(provenances.map { |source| source || :heuristic }.tally)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAiBridge
4
- VERSION = '5.2.1'
4
+ VERSION = '5.3.0'
5
5
  end
data/server.json CHANGED
@@ -7,6 +7,6 @@
7
7
  "url": "https://github.com/igmarin/rails-ai-bridge",
8
8
  "source": "github"
9
9
  },
10
- "version": "5.2.1",
10
+ "version": "5.3.0",
11
11
  "websiteUrl": "https://github.com/igmarin/rails-ai-bridge"
12
12
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-ai-bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Marin
@@ -151,8 +151,6 @@ files:
151
151
  - ".markdownlint.json"
152
152
  - ".mutant.yml"
153
153
  - ".reek.yml"
154
- - ".reviewer.toml"
155
- - ".rs-guardignore"
156
154
  - ".rspec"
157
155
  - ".rubocop.yml"
158
156
  - ".rubocop_todo.yml"
@@ -210,6 +208,7 @@ files:
210
208
  - lib/rails_ai_bridge/config/registry.rb
211
209
  - lib/rails_ai_bridge/config/rubydex.rb
212
210
  - lib/rails_ai_bridge/config/server.rb
211
+ - lib/rails_ai_bridge/config/static_analysis.rb
213
212
  - lib/rails_ai_bridge/configuration.rb
214
213
  - lib/rails_ai_bridge/context_provider.rb
215
214
  - lib/rails_ai_bridge/database_size.rb
@@ -254,6 +253,7 @@ files:
254
253
  - lib/rails_ai_bridge/introspectors/config_introspector.rb
255
254
  - lib/rails_ai_bridge/introspectors/controller_introspector.rb
256
255
  - lib/rails_ai_bridge/introspectors/controller_introspector/filter_extractor.rb
256
+ - lib/rails_ai_bridge/introspectors/controller_introspector/strong_params_provenance.rb
257
257
  - lib/rails_ai_bridge/introspectors/convention_detector.rb
258
258
  - lib/rails_ai_bridge/introspectors/database_stats_introspector.rb
259
259
  - lib/rails_ai_bridge/introspectors/devops_introspector.rb
@@ -281,6 +281,7 @@ files:
281
281
  - lib/rails_ai_bridge/introspectors/schema_introspector.rb
282
282
  - lib/rails_ai_bridge/introspectors/seeds_introspector.rb
283
283
  - lib/rails_ai_bridge/introspectors/semantic_introspector.rb
284
+ - lib/rails_ai_bridge/introspectors/static_prism_scanner.rb
284
285
  - lib/rails_ai_bridge/introspectors/stimulus_introspector.rb
285
286
  - lib/rails_ai_bridge/introspectors/test_introspector.rb
286
287
  - lib/rails_ai_bridge/introspectors/turbo_introspector.rb
@@ -416,10 +417,6 @@ files:
416
417
  - lib/rails_ai_bridge/service.rb
417
418
  - lib/rails_ai_bridge/service/result.rb
418
419
  - lib/rails_ai_bridge/service_errors.rb
419
- - lib/rails_ai_bridge/services/app_introspection_service.rb
420
- - lib/rails_ai_bridge/services/configuration_service.rb
421
- - lib/rails_ai_bridge/services/context_generation_service.rb
422
- - lib/rails_ai_bridge/services/file_management_service.rb
423
420
  - lib/rails_ai_bridge/static_app.rb
424
421
  - lib/rails_ai_bridge/tasks/rails_ai_bridge.rake
425
422
  - lib/rails_ai_bridge/tool_result_cache.rb
@@ -454,6 +451,7 @@ files:
454
451
  - lib/rails_ai_bridge/tools/model_details/single_model_formatter.rb
455
452
  - lib/rails_ai_bridge/tools/model_details/standard_formatter.rb
456
453
  - lib/rails_ai_bridge/tools/model_details/summary_formatter.rb
454
+ - lib/rails_ai_bridge/tools/provenance_lines.rb
457
455
  - lib/rails_ai_bridge/tools/query.rb
458
456
  - lib/rails_ai_bridge/tools/query/guard.rb
459
457
  - lib/rails_ai_bridge/tools/query/payload_formatter.rb
data/.reviewer.toml DELETED
@@ -1,13 +0,0 @@
1
- provider = "deepseek"
2
- model = "deepseek-v4-pro"
3
- max_tokens = 16384
4
- temperature = 0.1
5
- llm_timeout_secs = 240
6
-
7
- # Custom review prompt at .github/review-prompt.md
8
- # Loaded automatically via --prompt-file in CI and pre-commit hook.
9
-
10
- # Local mode: review staged changes (git diff --cached) by default.
11
- # To review the full branch against origin/main (same as a PR would):
12
- # rs-guard --base origin/main
13
- # Or set diff_base here and override with --base "" for staged-only.
data/.rs-guardignore DELETED
@@ -1,26 +0,0 @@
1
- # rs-guard ignore file — paths excluded from AI code review
2
- # Gitignore-style syntax. v1.8.0+ feature.
3
-
4
- # Generated coverage data
5
- coverage/
6
-
7
- # Combustion dummy app fixtures (not reviewable source)
8
- spec/internal/
9
-
10
- # Generated graph/code intelligence data
11
- graphify-out/
12
- .codegraph/
13
-
14
- # Built gems
15
- *.gem
16
-
17
- # Bundler
18
- vendor/bundle/
19
-
20
- # Documentation output
21
- .yardoc/
22
- doc/
23
-
24
- # Temporary files
25
- *.tmp
26
- *.log