Module: ShapeupCli::Output
- Defined in:
- lib/shapeup_cli/output.rb
Class Method Summary collapse
- .extract_data(result) ⇒ Object
-
.parse_mode(args) ⇒ Object
Parse output mode flags from args, returns [mode, remaining_args].
-
.render(result, breadcrumbs: [], mode: :styled, summary: nil) ⇒ Object
Render a tool result with breadcrumbs in the specified output mode.
Class Method Details
.extract_data(result) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shapeup_cli/output.rb', line 46 def self.extract_data(result) return result unless result.is_a?(Hash) # MCP tool results come wrapped: { content: [{ type: "text", text: "..." }] } if result["content"]&.is_a?(Array) text = result["content"].filter_map { |c| c["text"] if c["type"] == "text" }.join JSON.parse(text) rescue text else result end end |
.parse_mode(args) ⇒ Object
Parse output mode flags from args, returns [mode, remaining_args]
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shapeup_cli/output.rb', line 6 def self.parse_mode(args) mode = nil remaining = [] args.each do |arg| case arg when "--json" then mode = :json when "--md", "-m" then mode = :markdown when "--agent" then mode = :agent when "--quiet", "-q" then mode = :agent when "--ids-only" then mode = :ids_only else remaining << arg end end # Default: auto-detect from TTY. Piped output → JSON, terminal → styled. mode ||= Config.piped? ? :json : :styled [ mode, remaining ] end |
.render(result, breadcrumbs: [], mode: :styled, summary: nil) ⇒ Object
Render a tool result with breadcrumbs in the specified output mode
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shapeup_cli/output.rb', line 28 def self.render(result, breadcrumbs: [], mode: :styled, summary: nil) # Extract text content from MCP tool result data = extract_data(result) case mode when :json render_json(data, breadcrumbs: , summary: summary) when :agent render_agent(data) when :markdown render_markdown(data, summary: summary) when :ids_only render_ids_only(data) else render_styled(data, breadcrumbs: , summary: summary) end end |