Module: Legion::Extensions::Agentic::Social::Conflict::Runners::Conflict
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/social/conflict/runners/conflict.rb
Instance Method Summary collapse
- #active_conflicts ⇒ Object
- #add_exchange(conflict_id:, speaker:, message:) ⇒ Object
- #check_stale_conflicts ⇒ Object
- #get_conflict(conflict_id:) ⇒ Object
- #recommended_posture(severity:) ⇒ Object
- #register_conflict(parties:, severity:, description:) ⇒ Object
- #resolve_conflict(conflict_id:, outcome:, resolution_notes: nil) ⇒ Object
Instance Method Details
#active_conflicts ⇒ Object
65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 65 def active_conflicts(**) conflicts = conflict_log.active_conflicts log.debug "[conflict] active: count=#{conflicts.size}" { conflicts: conflicts, count: conflicts.size } end |
#add_exchange(conflict_id:, speaker:, message:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 22 def add_exchange(conflict_id:, speaker:, message:, **) result = conflict_log.add_exchange(conflict_id, speaker: speaker, message: ) if result log.debug "[conflict] exchange: id=#{conflict_id[0..7]} speaker=#{speaker}" { recorded: true } else log.debug "[conflict] exchange failed: id=#{conflict_id[0..7]} not found" { error: :not_found } end end |
#check_stale_conflicts ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 71 def check_stale_conflicts(**) active = conflict_log.active_conflicts stale = active.select { |c| Time.now.utc - c[:created_at] > Helpers::Severity::STALE_CONFLICT_TIMEOUT } stale.each do |c| = 'conflict marked stale — no resolution after 24h' if Helpers::LlmEnhancer.available? age_hours = (Time.now.utc - c[:created_at]) / 3600.0 analysis = Helpers::LlmEnhancer.analyze_stale_conflict( description: c[:description], severity: c[:severity], age_hours: age_hours, exchange_count: c[:exchanges].size ) = "conflict marked stale — #{analysis[:analysis]} (recommendation: #{analysis[:recommendation]})" if analysis end conflict_log.add_exchange(c[:conflict_id], speaker: :system, message: ) end stale_ids = stale.map { |c| c[:conflict_id] } log.debug "[conflict] stale check: active=#{active.size} stale=#{stale.size}" { checked: active.size, stale_count: stale.size, stale_ids: stale_ids } end |
#get_conflict(conflict_id:) ⇒ Object
59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 59 def get_conflict(conflict_id:, **) conflict = conflict_log.get(conflict_id) log.debug "[conflict] get: id=#{conflict_id[0..7]} found=#{!conflict.nil?}" conflict ? { found: true, conflict: conflict } : { found: false } end |
#recommended_posture(severity:) ⇒ Object
95 96 97 98 99 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 95 def recommended_posture(severity:, **) posture = Helpers::Severity.recommended_posture(severity) log.debug "[conflict] posture: severity=#{severity} posture=#{posture}" { severity: severity, posture: posture } end |
#register_conflict(parties:, severity:, description:) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 13 def register_conflict(parties:, severity:, description:, **) return { error: :invalid_severity, valid: Helpers::Severity::LEVELS } unless Helpers::Severity.valid_level?(severity) id = conflict_log.record(parties: parties, severity: severity, description: description) conflict = conflict_log.get(id) log.info "[conflict] registered: id=#{id[0..7]} severity=#{severity} posture=#{conflict[:posture]} parties=#{parties.join(',')}" { conflict_id: id, severity: severity, posture: conflict[:posture] } end |
#resolve_conflict(conflict_id:, outcome:, resolution_notes: nil) ⇒ Object
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 |
# File 'lib/legion/extensions/agentic/social/conflict/runners/conflict.rb', line 33 def resolve_conflict(conflict_id:, outcome:, resolution_notes: nil, **) conflict = conflict_log.get(conflict_id) unless conflict log.debug "[conflict] resolve failed: id=#{conflict_id[0..7]} not found" return { error: :not_found } end if resolution_notes.nil? && Helpers::LlmEnhancer.available? llm_result = Helpers::LlmEnhancer.suggest_resolution( description: conflict[:description], severity: conflict[:severity], exchanges: conflict[:exchanges] ) resolution_notes = llm_result[:resolution_notes] if llm_result end result = conflict_log.resolve(conflict_id, outcome: outcome, resolution_notes: resolution_notes) if result log.info "[conflict] resolved: id=#{conflict_id[0..7]} outcome=#{outcome}" { resolved: true, outcome: outcome } else log.debug "[conflict] resolve failed: id=#{conflict_id[0..7]} not found" { error: :not_found } end end |