Class: Woods::MCP::Renderers::PlainRenderer
- Inherits:
-
ToolResponseRenderer
- Object
- ToolResponseRenderer
- Woods::MCP::Renderers::PlainRenderer
- Defined in:
- lib/woods/mcp/renderers/plain_renderer.rb
Overview
Renders MCP tool responses as plain text with === dividers. Lightweight fallback format with no markup.
Constant Summary collapse
- DIVIDER =
('=' * 60).freeze
Constants inherited from ToolResponseRenderer
ToolResponseRenderer::VALID_FORMATS
Instance Method Summary collapse
-
#render_default(data) ⇒ String
Plain text output.
- #render_dependencies(data) ⇒ Object
- #render_dependents(data) ⇒ Object
- #render_framework(data) ⇒ Object
- #render_graph_analysis(data) ⇒ Object
- #render_lookup(data) ⇒ Object
- #render_pagerank(data) ⇒ Object
- #render_recent_changes(data) ⇒ Object
- #render_search(data) ⇒ Object
- #render_structure(data) ⇒ Object
Methods inherited from ToolResponseRenderer
Instance Method Details
#render_default(data) ⇒ String
Returns Plain text output.
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 213 def render_default(data) case data when Hash data.map { |k, v| "#{k}: #{v}" }.join("\n") when Array data.map { |item| " #{item}" }.join("\n") else data.to_s end end |
#render_dependencies(data) ⇒ Object
78 79 80 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 78 def render_dependencies(data, **) render_plain_traversal('Dependencies', data) end |
#render_dependents(data) ⇒ Object
82 83 84 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 82 def render_dependents(data, **) render_plain_traversal('Dependents', data) end |
#render_framework(data) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 175 def render_framework(data, **) keyword = fetch_key(data, :keyword) count = fetch_key(data, :result_count, 0) results = fetch_key(data, :results, []) lines = [] lines << "Framework: \"#{keyword}\" (#{count} results)" lines << DIVIDER results.each do |r| ident = fetch_key(r, :identifier) type = fetch_key(r, :type) lines << " #{ident} (#{type})" end lines.join("\n").rstrip end |
#render_graph_analysis(data) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 127 def render_graph_analysis(data, **) lines = [] lines << 'Graph Analysis' lines << DIVIDER stats = fetch_key(data, :stats) if stats.is_a?(Hash) stats.each { |k, v| lines << " #{k}: #{v}" } lines << '' end %w[orphans dead_ends hubs cycles bridges].each do |section| items = fetch_key(data, section) next unless items.is_a?(Array) && items.any? lines << "#{section.tr('_', ' ').upcase}:" items.each do |item| lines << if item.is_a?(Hash) " #{item['identifier']} (#{item['type']}) - #{item['dependent_count']} dependents" else " #{item}" end end total_key = "#{section}_total" lines << " (showing #{items.size} of #{data[total_key]})" if data[total_key] lines << '' end lines.join("\n").rstrip end |
#render_lookup(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 11 def render_lookup(data, **) return 'Unit not found' unless data.is_a?(Hash) && data['identifier'] lines = [] lines << "#{data['identifier']} (#{data['type']})" lines << DIVIDER lines << "File: #{data['file_path']}" if data['file_path'] lines << "Namespace: #{data['namespace']}" if data['namespace'] lines << '' if data['metadata'].is_a?(Hash) && data['metadata'].any? lines << 'Metadata:' data['metadata'].each do |key, value| case value when Array next if value.empty? lines << " #{key}:" value.each do |item| lines << " - #{item.is_a?(Hash) ? item.map { |k, v| "#{k}: #{v}" }.join(', ') : item}" end when Hash lines << " #{key}: #{value.map { |k, v| "#{k}=#{v}" }.join(', ')}" else lines << " #{key}: #{value}" end end lines << '' end if data['source_code'] lines << 'Source:' lines << DIVIDER lines << data['source_code'].chomp lines << DIVIDER lines << '' end if data['dependencies'].is_a?(Array) && data['dependencies'].any? lines << "Dependencies: #{data['dependencies'].join(', ')}" end if data['dependents'].is_a?(Array) && data['dependents'].any? lines << "Dependents: #{data['dependents'].join(', ')}" end lines.join("\n").rstrip end |
#render_pagerank(data) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 159 def render_pagerank(data, **) lines = [] lines << "PageRank Scores (ranking #{fetch_key(data, :total_nodes)} graph nodes)" lines << DIVIDER results = fetch_key(data, :results, []) results.each_with_index do |r, i| ident = fetch_key(r, :identifier) type = fetch_key(r, :type) score = fetch_key(r, :score) lines << " #{i + 1}. #{ident} (#{type}) - #{score}" end lines.join("\n").rstrip end |
#render_recent_changes(data) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 193 def render_recent_changes(data, **) count = fetch_key(data, :result_count, 0) results = fetch_key(data, :results, []) lines = [] lines << "Recent Changes (#{count} units)" lines << DIVIDER results.each do |r| ident = fetch_key(r, :identifier) type = fetch_key(r, :type) modified = fetch_key(r, :last_modified) || '-' lines << " #{ident} (#{type}) - #{modified}" end lines.join("\n").rstrip end |
#render_search(data) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 60 def render_search(data, **) query = fetch_key(data, :query) count = fetch_key(data, :result_count, 0) results = fetch_key(data, :results, []) lines = [] lines << "Search: \"#{query}\" (#{count} results)" lines << DIVIDER results.each do |r| ident = fetch_key(r, :identifier) type = fetch_key(r, :type) lines << " #{ident} (#{type})" end lines.join("\n").rstrip end |
#render_structure(data) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/woods/mcp/renderers/plain_renderer.rb', line 86 def render_structure(data, **) manifest = fetch_key(data, :manifest, {}) lines = [] lines << 'Codebase Structure' lines << DIVIDER %w[rails_version ruby_version git_branch git_sha extracted_at].each do |key| lines << " #{key}: #{manifest[key]}" if manifest[key] end lines << " units_indexed: #{manifest['total_units']}" if manifest['total_units'] template_engines = fetch_key(data, :template_engines) if template_engines.is_a?(Array) && template_engines.any? lines << " template_engines: #{template_engines.join(', ')}" end counts = manifest['counts'] if counts.is_a?(Hash) && counts.any? lines << '' lines << 'Unit counts:' counts.sort_by { |_k, v| -v }.each { |type, count| lines << " #{type}: #{count}" } end summary = fetch_key(data, :summary) if summary lines << '' lines << DIVIDER lines << summary end lines << '' lines << DIVIDER lines << 'Denominators:' lines << ' units_indexed (manifest, structure): total ExtractedUnits written.' lines << ' graph_nodes (pagerank, dependencies, dependents): units in the graph' lines << ' (excludes orphans with no incoming/outgoing edges).' lines << ' searchable_entries (codebase_retrieve): retriever-store entries including' lines << ' per-chunk rows. Always >= units_indexed.' lines.join("\n").rstrip end |