lex-resilience
Cognitive resilience and adversity recovery model for the LegionIO cognitive architecture. Based on Masten's resilience framework with antifragility support.
What It Does
Automatically detects adversity events from tick results (prediction failures, trust violations, conflict escalation, resource depletion, emotional shock) and tracks their recovery over time. Four resilience dimensions — elasticity (recovery speed), robustness (resistance to disruption), adaptability (strategy adjustment), and growth (improving from adversity) — are updated via EMA. After enough consecutive recoveries, a growth bonus builds, enabling antifragile classification.
Usage
client = Legion::Extensions::Resilience::Client.new
# Update on each tick (auto-detects adversities from tick results)
result = client.update_resilience(
tick_results: {
prediction_engine: { error_rate: 0.8 },
emotional_evaluation: { arousal: 0.95 }
}
)
# => { active_adversities: 2, resolved_this_tick: 0,
# composite_score: 0.48, classification: :fragile, growth_bonus: 0.0 }
# Register adversity manually
client.register_adversity(type: :trust_violation, severity: :major)
# Check resilience status
client.resilience_status
# => { dimensions: { elasticity: 0.45, robustness: 0.52, adaptability: 0.48, growth: 0.50 },
# composite: 0.49, class: :fragile, trend: :stable, ... }
# Dimension detail
client.dimension_detail(dimension: :elasticity)
# Adversity report
client.adversity_report
# => { active: [...], by_type: {...}, total: 5, worst: 0.5, avg_speed: 0.03 }
client.resilience_statsClassifications
| Class | Composite Score |
|---|---|
:antifragile |
>= 0.7 |
:resilient |
>= 0.5 |
:fragile |
>= 0.3 |
:brittle |
< 0.3 |
Adversity Types
:prediction_failure, :trust_violation, :conflict_escalation, :resource_depletion, :communication_failure, :goal_failure, :emotional_shock, :system_error
Development
bundle install
bundle exec rspec
bundle exec rubocopLicense
MIT