Module: RubyCoded::Chat::PlanClarificationParser
- Defined in:
- lib/ruby_coded/chat/plan_clarification_parser.rb
Overview
Parses <clarification> tags from LLM responses in plan mode. Extracts a single question and its options for the UI.
Constant Summary collapse
- CLARIFICATION_REGEX =
%r{<clarification>\s*(.*?)\s*</clarification>}m- QUESTION_REGEX =
%r{<question>\s*(.*?)\s*</question>}m- OPTION_REGEX =
%r{<option>\s*(.*?)\s*</option>}m
Class Method Summary collapse
- .clarification?(content) ⇒ Boolean
-
.parse(content) ⇒ Object
Returns { question: String, options: [String], preamble: String } or nil if no clarification tags are found.
- .strip_clarification(content) ⇒ Object
Class Method Details
.clarification?(content) ⇒ Boolean
12 13 14 |
# File 'lib/ruby_coded/chat/plan_clarification_parser.rb', line 12 def self.clarification?(content) CLARIFICATION_REGEX.match?(content) end |
.parse(content) ⇒ Object
Returns { question: String, options: [String], preamble: String } or nil if no clarification tags are found.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby_coded/chat/plan_clarification_parser.rb', line 18 def self.parse(content) match = CLARIFICATION_REGEX.match(content) return nil unless match inner = match[1] question = QUESTION_REGEX.match(inner)&.[](1)&.strip = inner.scan(OPTION_REGEX).flatten.map(&:strip) return nil unless question && .size >= 2 preamble = content[0...match.begin(0)].strip { question: question, options: , preamble: preamble } end |
.strip_clarification(content) ⇒ Object
33 34 35 |
# File 'lib/ruby_coded/chat/plan_clarification_parser.rb', line 33 def self.strip_clarification(content) content.sub(CLARIFICATION_REGEX, "").strip end |