Module: Legion::MCP::PatternExchange
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/pattern_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/pattern_exchange.rb', line 14 def export_all(min_confidence: 0.5) PatternStore.patterns.filter_map do |_hash, pattern| next if (pattern[:confidence] || 0) < min_confidence PatternSchema.export(pattern) end end |
.export_to_file(path, min_confidence: 0.5) ⇒ Object
42 43 44 45 46 |
# File 'lib/legion/mcp/pattern_exchange.rb', line 42 def export_to_file(path, min_confidence: 0.5) data = export_all(min_confidence: min_confidence) File.write(path, ::JSON.pretty_generate(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 |
# File 'lib/legion/mcp/pattern_exchange.rb', line 22 def import_all(patterns, trust_level: :community) imported = 0 skipped = 0 Array(patterns).each do |external| next unless PatternSchema.validate_schema(external) internal = PatternSchema.import(external, trust_level: trust_level) if PatternStore.pattern_exists?(internal[:intent_hash]) skipped += 1 next end PatternStore.store(internal) imported += 1 end { imported: imported, skipped: skipped } end |
.import_from_file(path, trust_level: :community) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/legion/mcp/pattern_exchange.rb', line 48 def import_from_file(path, trust_level: :community) log.info('Starting legion.mcp.pattern_exchange.import_from_file') raw = File.read(path) patterns = ::JSON.parse(raw, symbolize_names: true) 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') log.error("PatternExchange#import_from_file failed: #{e.}") { error: e., imported: 0 } end |