Module: Mana::Knowledge

Defined in:
lib/mana/knowledge.rb

Overview

Runtime knowledge base — assembles information about ruby-mana from live code. No static files to maintain; the code IS the source of truth.

Class Method Summary collapse

Class Method Details

.query(topic) ⇒ Object

Query a topic using a cascading lookup strategy. Priority: mana docs > ruby env > ri (external docs) > runtime introspection > dump all. The fallback chain ensures we always return something useful.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mana/knowledge.rb', line 13

def query(topic)
  topic_key = topic.to_s.strip.downcase
  sections = all_sections

  # 1. Match mana's own sections (bidirectional substring match for flexibility)
  match = sections.find { |k, _| topic_key.include?(k) || k.include?(topic_key) }
  return "[source: mana]\n#{match.last}" if match

  # 2. Ruby environment info
  return "[source: ruby runtime]\n#{ruby_environment}" if topic_key == "ruby"

  # 3. Try ri (official Ruby documentation)
  ri_result = query_ri(topic.to_s.strip)
  return "[source: ri (Ruby official docs)]\n#{ri_result}" if ri_result

  # 4. Try runtime introspection
  introspect_result = query_introspect(topic.to_s.strip)
  return "[source: ruby introspection]\n#{introspect_result}" if introspect_result

  # 5. Fallback: dump all mana sections so the LLM has full context
  "[source: mana]\n#{sections.values.join("\n\n")}"
end