Module: RailsAiContext::Confidence
- Defined in:
- lib/rails_ai_context/confidence.rb
Overview
Confidence tags for AST introspection results. Shared across tools and introspectors without creating cross-layer dependencies.
VERIFIED: value extracted from a static, deterministic AST node
(symbol literals, string literals, integers, booleans).
INFERRED: value involves dynamic expressions, metaprogramming,
or runtime-only constructs that AST cannot fully resolve.
Constant Summary collapse
- VERIFIED =
"[VERIFIED]"- INFERRED =
"[INFERRED]"
Class Method Summary collapse
-
.for_node(node) ⇒ Object
Determine confidence level for a Prism call node’s arguments.
-
.static_node?(node) ⇒ Boolean
Recursively check if a node is a static literal.
Class Method Details
.for_node(node) ⇒ Object
Determine confidence level for a Prism call node’s arguments. Returns VERIFIED if all arguments are static literals, INFERRED if any argument is a dynamic expression.
19 20 21 22 23 24 25 |
# File 'lib/rails_ai_context/confidence.rb', line 19 def self.for_node(node) args = node.arguments&.arguments return VERIFIED unless args static = args.all? { |a| static_node?(a) } static ? VERIFIED : INFERRED end |
.static_node?(node) ⇒ Boolean
Recursively check if a node is a static literal.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_ai_context/confidence.rb', line 28 def self.static_node?(node) case node when Prism::SymbolNode, Prism::StringNode, Prism::IntegerNode, Prism::FloatNode, Prism::TrueNode, Prism::FalseNode, Prism::NilNode, Prism::ConstantReadNode, Prism::ConstantPathNode true when Prism::ArrayNode node.elements.all? { |e| static_node?(e) } when Prism::HashNode node.elements.all? { |e| e.is_a?(Prism::AssocNode) && static_node?(e.key) && static_node?(e.value) } when Prism::KeywordHashNode node.elements.all? { |e| e.is_a?(Prism::AssocNode) && static_node?(e.key) && static_node?(e.value) } else false end end |