Module: Legion::MCP::Patterns::Exchange
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/patterns/exchange.rb
Class Method Summary collapse
- .export_all(min_confidence: 0.5) ⇒ Object
- .export_to_file(path, min_confidence: 0.5) ⇒ Object
- .import_all(patterns, trust_level: :community) ⇒ Object
- .import_from_file(path, trust_level: :community) ⇒ Object
Class Method Details
.export_all(min_confidence: 0.5) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/legion/mcp/patterns/exchange.rb', line 14 def export_all(min_confidence: 0.5) Patterns::Store.patterns.filter_map do |_hash, pattern| next if (pattern[:confidence] || 0) < min_confidence Patterns::Schema.export(pattern) end end |
.export_to_file(path, min_confidence: 0.5) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/legion/mcp/patterns/exchange.rb', line 43 def export_to_file(path, min_confidence: 0.5) log.debug("[mcp][pattern_exchange] action=export_to_file path=#{path} min_confidence=#{min_confidence}") data = export_all(min_confidence: min_confidence) File.write(path, Legion::JSON.dump(data)) { exported: data.size, path: path } end |
.import_all(patterns, trust_level: :community) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/mcp/patterns/exchange.rb', line 22 def import_all(patterns, trust_level: :community) log.debug("[mcp][pattern_exchange] action=import_all count=#{Array(patterns).size} trust_level=#{trust_level}") imported = 0 skipped = 0 Array(patterns).each do |external| next unless Patterns::Schema.validate_schema(external) internal = Patterns::Schema.import(external, trust_level: trust_level) if Patterns::Store.pattern_exists?(internal[:intent_hash]) skipped += 1 next end Patterns::Store.store(internal) imported += 1 end { imported: imported, skipped: skipped } end |
.import_from_file(path, trust_level: :community) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/legion/mcp/patterns/exchange.rb', line 50 def import_from_file(path, trust_level: :community) log.debug("[mcp][pattern_exchange] action=import_from_file path=#{path} trust_level=#{trust_level}") raw = File.read(path) patterns = Legion::JSON.load(raw) patterns = [patterns] if patterns.is_a?(Hash) import_all(patterns, trust_level: trust_level) rescue StandardError => e handle_exception(e, level: :error, operation: 'legion.mcp.pattern_exchange.import_from_file') { error: e., imported: 0 } end |