lex-agentic-affect 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-affect.gemspec +30 -0
- data/lib/legion/extensions/agentic/affect/appraisal/client.rb +20 -0
- data/lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal.rb +112 -0
- data/lib/legion/extensions/agentic/affect/appraisal/helpers/appraisal_engine.rb +129 -0
- data/lib/legion/extensions/agentic/affect/appraisal/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/affect/appraisal/runners/appraisal.rb +105 -0
- data/lib/legion/extensions/agentic/affect/appraisal/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/appraisal.rb +19 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/client.rb +19 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/empathy_engine.rb +151 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb +92 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/runners/cognitive_empathy.rb +93 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy.rb +20 -0
- data/lib/legion/extensions/agentic/affect/contagion/client.rb +28 -0
- data/lib/legion/extensions/agentic/affect/contagion/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/affect/contagion/helpers/contagion_engine.rb +184 -0
- data/lib/legion/extensions/agentic/affect/contagion/helpers/meme.rb +97 -0
- data/lib/legion/extensions/agentic/affect/contagion/runners/cognitive_contagion.rb +125 -0
- data/lib/legion/extensions/agentic/affect/contagion/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/contagion.rb +19 -0
- data/lib/legion/extensions/agentic/affect/defusion/client.rb +28 -0
- data/lib/legion/extensions/agentic/affect/defusion/helpers/constants.rb +64 -0
- data/lib/legion/extensions/agentic/affect/defusion/helpers/defusion_engine.rb +167 -0
- data/lib/legion/extensions/agentic/affect/defusion/helpers/thought.rb +92 -0
- data/lib/legion/extensions/agentic/affect/defusion/runners/cognitive_defusion.rb +127 -0
- data/lib/legion/extensions/agentic/affect/defusion/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/defusion.rb +19 -0
- data/lib/legion/extensions/agentic/affect/emotion/actors/momentum_decay.rb +45 -0
- data/lib/legion/extensions/agentic/affect/emotion/client.rb +36 -0
- data/lib/legion/extensions/agentic/affect/emotion/helpers/baseline.rb +52 -0
- data/lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb +52 -0
- data/lib/legion/extensions/agentic/affect/emotion/helpers/valence.rb +92 -0
- data/lib/legion/extensions/agentic/affect/emotion/runners/gut.rb +102 -0
- data/lib/legion/extensions/agentic/affect/emotion/runners/valence.rb +120 -0
- data/lib/legion/extensions/agentic/affect/emotion/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/emotion.rb +20 -0
- data/lib/legion/extensions/agentic/affect/empathy/client.rb +21 -0
- data/lib/legion/extensions/agentic/affect/empathy/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/affect/empathy/helpers/mental_model.rb +185 -0
- data/lib/legion/extensions/agentic/affect/empathy/helpers/model_store.rb +88 -0
- data/lib/legion/extensions/agentic/affect/empathy/runners/empathy.rb +173 -0
- data/lib/legion/extensions/agentic/affect/empathy/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/empathy.rb +20 -0
- data/lib/legion/extensions/agentic/affect/fatigue/client.rb +26 -0
- data/lib/legion/extensions/agentic/affect/fatigue/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/affect/fatigue/helpers/energy_model.rb +181 -0
- data/lib/legion/extensions/agentic/affect/fatigue/helpers/fatigue_store.rb +146 -0
- data/lib/legion/extensions/agentic/affect/fatigue/runners/fatigue.rb +89 -0
- data/lib/legion/extensions/agentic/affect/fatigue/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/fatigue.rb +19 -0
- data/lib/legion/extensions/agentic/affect/flow/client.rb +25 -0
- data/lib/legion/extensions/agentic/affect/flow/helpers/constants.rb +84 -0
- data/lib/legion/extensions/agentic/affect/flow/helpers/flow_detector.rb +166 -0
- data/lib/legion/extensions/agentic/affect/flow/runners/flow.rb +129 -0
- data/lib/legion/extensions/agentic/affect/flow/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/flow.rb +18 -0
- data/lib/legion/extensions/agentic/affect/interoception/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/affect/interoception/client.rb +28 -0
- data/lib/legion/extensions/agentic/affect/interoception/helpers/body_budget.rb +152 -0
- data/lib/legion/extensions/agentic/affect/interoception/helpers/constants.rb +68 -0
- data/lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb +75 -0
- data/lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb +101 -0
- data/lib/legion/extensions/agentic/affect/interoception/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/interoception.rb +20 -0
- data/lib/legion/extensions/agentic/affect/mood/client.rb +21 -0
- data/lib/legion/extensions/agentic/affect/mood/helpers/constants.rb +78 -0
- data/lib/legion/extensions/agentic/affect/mood/helpers/mood_state.rb +154 -0
- data/lib/legion/extensions/agentic/affect/mood/runners/mood.rb +122 -0
- data/lib/legion/extensions/agentic/affect/mood/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/mood.rb +18 -0
- data/lib/legion/extensions/agentic/affect/motivation/client.rb +26 -0
- data/lib/legion/extensions/agentic/affect/motivation/helpers/constants.rb +48 -0
- data/lib/legion/extensions/agentic/affect/motivation/helpers/drive_state.rb +98 -0
- data/lib/legion/extensions/agentic/affect/motivation/helpers/motivation_store.rb +106 -0
- data/lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb +165 -0
- data/lib/legion/extensions/agentic/affect/motivation/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/motivation.rb +19 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/actors/auto_regulate.rb +45 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/client.rb +28 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/helpers/constants.rb +82 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event.rb +98 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/helpers/llm_enhancer.rb +88 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/helpers/reappraisal_engine.rb +153 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/runners/cognitive_reappraisal.rb +164 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/reappraisal.rb +20 -0
- data/lib/legion/extensions/agentic/affect/regulation/client.rb +25 -0
- data/lib/legion/extensions/agentic/affect/regulation/helpers/constants.rb +71 -0
- data/lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb +175 -0
- data/lib/legion/extensions/agentic/affect/regulation/runners/emotional_regulation.rb +127 -0
- data/lib/legion/extensions/agentic/affect/regulation/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/regulation.rb +18 -0
- data/lib/legion/extensions/agentic/affect/resilience/client.rb +27 -0
- data/lib/legion/extensions/agentic/affect/resilience/helpers/adversity_tracker.rb +130 -0
- data/lib/legion/extensions/agentic/affect/resilience/helpers/constants.rb +79 -0
- data/lib/legion/extensions/agentic/affect/resilience/helpers/resilience_model.rb +165 -0
- data/lib/legion/extensions/agentic/affect/resilience/runners/resilience.rb +150 -0
- data/lib/legion/extensions/agentic/affect/resilience/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/resilience.rb +19 -0
- data/lib/legion/extensions/agentic/affect/resonance/client.rb +24 -0
- data/lib/legion/extensions/agentic/affect/resonance/helpers/category.rb +75 -0
- data/lib/legion/extensions/agentic/affect/resonance/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/affect/resonance/helpers/resonance_engine.rb +115 -0
- data/lib/legion/extensions/agentic/affect/resonance/runners/cognitive_resonance.rb +94 -0
- data/lib/legion/extensions/agentic/affect/resonance/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/resonance.rb +19 -0
- data/lib/legion/extensions/agentic/affect/reward/client.rb +26 -0
- data/lib/legion/extensions/agentic/affect/reward/helpers/constants.rb +67 -0
- data/lib/legion/extensions/agentic/affect/reward/helpers/reward_signal.rb +178 -0
- data/lib/legion/extensions/agentic/affect/reward/helpers/reward_store.rb +142 -0
- data/lib/legion/extensions/agentic/affect/reward/runners/reward.rb +92 -0
- data/lib/legion/extensions/agentic/affect/reward/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/reward.rb +19 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/client.rb +29 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/helpers/body_state.rb +69 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/helpers/marker_store.rb +160 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb +74 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb +132 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/version.rb +13 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker.rb +20 -0
- data/lib/legion/extensions/agentic/affect/version.rb +11 -0
- data/lib/legion/extensions/agentic/affect.rb +34 -0
- data/spec/legion/extensions/agentic/affect/appraisal/client_spec.rb +52 -0
- data/spec/legion/extensions/agentic/affect/appraisal/helpers/appraisal_engine_spec.rb +161 -0
- data/spec/legion/extensions/agentic/affect/appraisal/helpers/appraisal_spec.rb +175 -0
- data/spec/legion/extensions/agentic/affect/appraisal/helpers/constants_spec.rb +49 -0
- data/spec/legion/extensions/agentic/affect/appraisal/runners/appraisal_spec.rb +116 -0
- data/spec/legion/extensions/agentic/affect/cognitive_empathy/client_spec.rb +62 -0
- data/spec/legion/extensions/agentic/affect/cognitive_empathy/helpers/empathy_engine_spec.rb +316 -0
- data/spec/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective_spec.rb +132 -0
- data/spec/legion/extensions/agentic/affect/cognitive_empathy/runners/cognitive_empathy_spec.rb +200 -0
- data/spec/legion/extensions/agentic/affect/contagion/client_spec.rb +63 -0
- data/spec/legion/extensions/agentic/affect/contagion/helpers/constants_spec.rb +86 -0
- data/spec/legion/extensions/agentic/affect/contagion/helpers/contagion_engine_spec.rb +241 -0
- data/spec/legion/extensions/agentic/affect/contagion/helpers/meme_spec.rb +160 -0
- data/spec/legion/extensions/agentic/affect/contagion/runners/cognitive_contagion_spec.rb +211 -0
- data/spec/legion/extensions/agentic/affect/defusion/client_spec.rb +80 -0
- data/spec/legion/extensions/agentic/affect/defusion/helpers/constants_spec.rb +84 -0
- data/spec/legion/extensions/agentic/affect/defusion/helpers/defusion_engine_spec.rb +250 -0
- data/spec/legion/extensions/agentic/affect/defusion/helpers/thought_spec.rb +178 -0
- data/spec/legion/extensions/agentic/affect/defusion/runners/cognitive_defusion_spec.rb +185 -0
- data/spec/legion/extensions/agentic/affect/emotion/actors/momentum_decay_spec.rb +46 -0
- data/spec/legion/extensions/agentic/affect/emotion/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/affect/emotion/helpers/baseline_spec.rb +48 -0
- data/spec/legion/extensions/agentic/affect/emotion/helpers/momentum_spec.rb +45 -0
- data/spec/legion/extensions/agentic/affect/emotion/helpers/valence_spec.rb +91 -0
- data/spec/legion/extensions/agentic/affect/emotion/runners/gut_spec.rb +73 -0
- data/spec/legion/extensions/agentic/affect/emotion/runners/valence_spec.rb +67 -0
- data/spec/legion/extensions/agentic/affect/empathy/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/affect/empathy/helpers/constants_spec.rb +23 -0
- data/spec/legion/extensions/agentic/affect/empathy/helpers/mental_model_spec.rb +150 -0
- data/spec/legion/extensions/agentic/affect/empathy/helpers/model_store_spec.rb +94 -0
- data/spec/legion/extensions/agentic/affect/empathy/runners/empathy_spec.rb +127 -0
- data/spec/legion/extensions/agentic/affect/fatigue/client_spec.rb +66 -0
- data/spec/legion/extensions/agentic/affect/fatigue/helpers/constants_spec.rb +130 -0
- data/spec/legion/extensions/agentic/affect/fatigue/helpers/energy_model_spec.rb +281 -0
- data/spec/legion/extensions/agentic/affect/fatigue/helpers/fatigue_store_spec.rb +157 -0
- data/spec/legion/extensions/agentic/affect/fatigue/runners/fatigue_spec.rb +127 -0
- data/spec/legion/extensions/agentic/affect/flow/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/affect/flow/helpers/constants_spec.rb +112 -0
- data/spec/legion/extensions/agentic/affect/flow/helpers/flow_detector_spec.rb +268 -0
- data/spec/legion/extensions/agentic/affect/flow/runners/flow_spec.rb +222 -0
- data/spec/legion/extensions/agentic/affect/interoception/client_spec.rb +52 -0
- data/spec/legion/extensions/agentic/affect/interoception/helpers/body_budget_spec.rb +178 -0
- data/spec/legion/extensions/agentic/affect/interoception/helpers/somatic_marker_spec.rb +120 -0
- data/spec/legion/extensions/agentic/affect/interoception/runners/interoception_spec.rb +108 -0
- data/spec/legion/extensions/agentic/affect/mood/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/affect/mood/helpers/constants_spec.rb +29 -0
- data/spec/legion/extensions/agentic/affect/mood/helpers/mood_state_spec.rb +94 -0
- data/spec/legion/extensions/agentic/affect/mood/runners/mood_spec.rb +71 -0
- data/spec/legion/extensions/agentic/affect/motivation/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/affect/motivation/helpers/constants_spec.rb +111 -0
- data/spec/legion/extensions/agentic/affect/motivation/helpers/drive_state_spec.rb +183 -0
- data/spec/legion/extensions/agentic/affect/motivation/helpers/motivation_store_spec.rb +185 -0
- data/spec/legion/extensions/agentic/affect/motivation/runners/motivation_spec.rb +248 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/actors/auto_regulate_spec.rb +46 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/client_spec.rb +64 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/helpers/constants_spec.rb +102 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/helpers/emotional_event_spec.rb +177 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/helpers/llm_enhancer_spec.rb +161 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/helpers/reappraisal_engine_spec.rb +211 -0
- data/spec/legion/extensions/agentic/affect/reappraisal/runners/cognitive_reappraisal_spec.rb +312 -0
- data/spec/legion/extensions/agentic/affect/regulation/client_spec.rb +61 -0
- data/spec/legion/extensions/agentic/affect/regulation/helpers/constants_spec.rb +108 -0
- data/spec/legion/extensions/agentic/affect/regulation/helpers/regulation_model_spec.rb +200 -0
- data/spec/legion/extensions/agentic/affect/regulation/runners/emotional_regulation_spec.rb +190 -0
- data/spec/legion/extensions/agentic/affect/resilience/client_spec.rb +36 -0
- data/spec/legion/extensions/agentic/affect/resilience/helpers/adversity_tracker_spec.rb +164 -0
- data/spec/legion/extensions/agentic/affect/resilience/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/affect/resilience/helpers/resilience_model_spec.rb +133 -0
- data/spec/legion/extensions/agentic/affect/resilience/runners/resilience_spec.rb +150 -0
- data/spec/legion/extensions/agentic/affect/resonance/client_spec.rb +66 -0
- data/spec/legion/extensions/agentic/affect/resonance/cognitive_resonance_spec.rb +27 -0
- data/spec/legion/extensions/agentic/affect/resonance/helpers/category_spec.rb +146 -0
- data/spec/legion/extensions/agentic/affect/resonance/helpers/constants_spec.rb +104 -0
- data/spec/legion/extensions/agentic/affect/resonance/helpers/resonance_engine_spec.rb +189 -0
- data/spec/legion/extensions/agentic/affect/resonance/runners/cognitive_resonance_spec.rb +197 -0
- data/spec/legion/extensions/agentic/affect/reward/client_spec.rb +42 -0
- data/spec/legion/extensions/agentic/affect/reward/helpers/constants_spec.rb +91 -0
- data/spec/legion/extensions/agentic/affect/reward/helpers/reward_signal_spec.rb +296 -0
- data/spec/legion/extensions/agentic/affect/reward/helpers/reward_store_spec.rb +167 -0
- data/spec/legion/extensions/agentic/affect/reward/runners/reward_spec.rb +149 -0
- data/spec/legion/extensions/agentic/affect/somatic_marker/client_spec.rb +83 -0
- data/spec/legion/extensions/agentic/affect/somatic_marker/helpers/body_state_spec.rb +155 -0
- data/spec/legion/extensions/agentic/affect/somatic_marker/helpers/marker_store_spec.rb +233 -0
- data/spec/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker_spec.rb +172 -0
- data/spec/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker_spec.rb +181 -0
- data/spec/spec_helper.rb +46 -0
- metadata +302 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Defusion::Runners::CognitiveDefusion do
|
|
4
|
+
let(:engine) { Legion::Extensions::Agentic::Affect::Defusion::Helpers::DefusionEngine.new }
|
|
5
|
+
let(:client) { Legion::Extensions::Agentic::Affect::Defusion::Client.new(engine: engine) }
|
|
6
|
+
|
|
7
|
+
def reg(content: 'I will fail', thought_type: :belief, belief_strength: 0.8)
|
|
8
|
+
client.register_thought(content: content, thought_type: thought_type, belief_strength: belief_strength, engine: engine)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe '#register_thought' do
|
|
12
|
+
it 'returns success true for valid input' do
|
|
13
|
+
result = reg
|
|
14
|
+
expect(result[:success]).to be true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'returns the thought_id' do
|
|
18
|
+
result = reg
|
|
19
|
+
expect(result[:thought_id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns success false for invalid thought_type' do
|
|
23
|
+
result = client.register_thought(content: 'x', thought_type: :bad, belief_strength: 0.5, engine: engine)
|
|
24
|
+
expect(result[:success]).to be false
|
|
25
|
+
expect(result[:error]).to eq(:invalid_thought_type)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'accepts an injected engine' do
|
|
29
|
+
other_engine = Legion::Extensions::Agentic::Affect::Defusion::Helpers::DefusionEngine.new
|
|
30
|
+
result = client.register_thought(content: 'test', thought_type: :judgment, belief_strength: 0.5, engine: other_engine)
|
|
31
|
+
expect(result[:success]).to be true
|
|
32
|
+
expect(other_engine.thoughts.size).to eq(1)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#apply_defusion' do
|
|
37
|
+
let(:thought_id) { reg[:thought_id] }
|
|
38
|
+
|
|
39
|
+
it 'returns success and fusion reduction' do
|
|
40
|
+
result = client.apply_defusion(thought_id: thought_id, technique: :acceptance, engine: engine)
|
|
41
|
+
expect(result[:success]).to be true
|
|
42
|
+
expect(result[:reduction]).to be > 0.0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'returns success false for invalid thought_id' do
|
|
46
|
+
result = client.apply_defusion(thought_id: 'nope', technique: :labeling, engine: engine)
|
|
47
|
+
expect(result[:success]).to be false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns success false for invalid technique' do
|
|
51
|
+
result = client.apply_defusion(thought_id: thought_id, technique: :made_up, engine: engine)
|
|
52
|
+
expect(result[:success]).to be false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#apply_all_techniques' do
|
|
57
|
+
let(:thought_id) { reg[:thought_id] }
|
|
58
|
+
|
|
59
|
+
it 'applies all techniques and returns success' do
|
|
60
|
+
result = client.apply_all_techniques(thought_id: thought_id, engine: engine)
|
|
61
|
+
expect(result[:success]).to be true
|
|
62
|
+
expect(result[:total_applied]).to eq(Legion::Extensions::Agentic::Affect::Defusion::Helpers::Constants::DEFUSION_TECHNIQUES.size)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'returns success false for unknown thought' do
|
|
66
|
+
result = client.apply_all_techniques(thought_id: 'missing', engine: engine)
|
|
67
|
+
expect(result[:success]).to be false
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#visit_thought' do
|
|
72
|
+
let(:thought_id) { reg[:thought_id] }
|
|
73
|
+
|
|
74
|
+
it 'returns success with visit_count' do
|
|
75
|
+
result = client.visit_thought(thought_id: thought_id, engine: engine)
|
|
76
|
+
expect(result[:success]).to be true
|
|
77
|
+
expect(result[:visit_count]).to eq(1)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'returns success false for unknown thought' do
|
|
81
|
+
result = client.visit_thought(thought_id: 'missing', engine: engine)
|
|
82
|
+
expect(result[:success]).to be false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#fuse_thought' do
|
|
87
|
+
let(:thought_id) { reg[:thought_id] }
|
|
88
|
+
|
|
89
|
+
it 'increases fusion and returns enmeshed flag' do
|
|
90
|
+
result = client.fuse_thought(thought_id: thought_id, engine: engine)
|
|
91
|
+
expect(result[:success]).to be true
|
|
92
|
+
expect(result[:after]).to be > result[:before]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'returns success false for unknown thought' do
|
|
96
|
+
result = client.fuse_thought(thought_id: 'missing', engine: engine)
|
|
97
|
+
expect(result[:success]).to be false
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#enmeshed_thoughts' do
|
|
102
|
+
it 'returns count and thoughts array' do
|
|
103
|
+
reg
|
|
104
|
+
result = client.enmeshed_thoughts(engine: engine)
|
|
105
|
+
expect(result[:success]).to be true
|
|
106
|
+
expect(result[:count]).to be >= 1
|
|
107
|
+
expect(result[:thoughts]).to be_an(Array)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe '#defused_thoughts' do
|
|
112
|
+
it 'returns empty when no thoughts are defused' do
|
|
113
|
+
reg
|
|
114
|
+
result = client.defused_thoughts(engine: engine)
|
|
115
|
+
expect(result[:success]).to be true
|
|
116
|
+
expect(result[:count]).to eq(0)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'returns thought after being defused' do
|
|
120
|
+
tid = reg[:thought_id]
|
|
121
|
+
20.times { client.apply_defusion(thought_id: tid, technique: :acceptance, engine: engine) }
|
|
122
|
+
result = client.defused_thoughts(engine: engine)
|
|
123
|
+
expect(result[:count]).to be >= 1
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe '#ruminating_thoughts' do
|
|
128
|
+
it 'returns empty with no visits' do
|
|
129
|
+
reg
|
|
130
|
+
result = client.ruminating_thoughts(engine: engine)
|
|
131
|
+
expect(result[:count]).to eq(0)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'returns thought after enough visits' do
|
|
135
|
+
tid = reg[:thought_id]
|
|
136
|
+
Legion::Extensions::Agentic::Affect::Defusion::Helpers::Constants::RUMINATION_COUNT.times do
|
|
137
|
+
client.visit_thought(thought_id: tid, engine: engine)
|
|
138
|
+
end
|
|
139
|
+
result = client.ruminating_thoughts(engine: engine)
|
|
140
|
+
expect(result[:count]).to be >= 1
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
describe '#most_fused' do
|
|
145
|
+
it 'returns success with thoughts array' do
|
|
146
|
+
reg
|
|
147
|
+
result = client.most_fused(limit: 3, engine: engine)
|
|
148
|
+
expect(result[:success]).to be true
|
|
149
|
+
expect(result[:thoughts]).to be_an(Array)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe '#recommend_technique' do
|
|
154
|
+
let(:thought_id) { reg[:thought_id] }
|
|
155
|
+
|
|
156
|
+
it 'returns success with technique recommendation' do
|
|
157
|
+
result = client.recommend_technique(thought_id: thought_id, engine: engine)
|
|
158
|
+
expect(result[:success]).to be true
|
|
159
|
+
expect(result[:technique]).to be_a(Symbol)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'returns success false for unknown thought' do
|
|
163
|
+
result = client.recommend_technique(thought_id: 'missing', engine: engine)
|
|
164
|
+
expect(result[:success]).to be false
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
describe '#defusion_report' do
|
|
169
|
+
it 'returns success with full report' do
|
|
170
|
+
reg
|
|
171
|
+
result = client.defusion_report(engine: engine)
|
|
172
|
+
expect(result[:success]).to be true
|
|
173
|
+
expect(result[:total_thoughts]).to be >= 1
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe '#defusion_state' do
|
|
178
|
+
it 'returns full engine state' do
|
|
179
|
+
reg
|
|
180
|
+
result = client.defusion_state(engine: engine)
|
|
181
|
+
expect(result[:success]).to be true
|
|
182
|
+
expect(result).to have_key(:thoughts)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Stub the base class before loading the actor
|
|
4
|
+
module Legion
|
|
5
|
+
module Extensions
|
|
6
|
+
module Actors
|
|
7
|
+
class Every; end # rubocop:disable Lint/EmptyClass
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
$LOADED_FEATURES << 'legion/extensions/actors/every'
|
|
13
|
+
|
|
14
|
+
require_relative '../../../../../../../lib/legion/extensions/agentic/affect/emotion/actors/momentum_decay'
|
|
15
|
+
|
|
16
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Actor::MomentumDecay do
|
|
17
|
+
subject(:actor) { described_class.new }
|
|
18
|
+
|
|
19
|
+
describe '#runner_class' do
|
|
20
|
+
it { expect(actor.runner_class).to eq Legion::Extensions::Agentic::Affect::Emotion::Runners::Gut }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#runner_function' do
|
|
24
|
+
it { expect(actor.runner_function).to eq 'decay_momentum' }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#time' do
|
|
28
|
+
it { expect(actor.time).to eq 60 }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#run_now?' do
|
|
32
|
+
it { expect(actor.run_now?).to be false }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#use_runner?' do
|
|
36
|
+
it { expect(actor.use_runner?).to be false }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#check_subtask?' do
|
|
40
|
+
it { expect(actor.check_subtask?).to be false }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe '#generate_task?' do
|
|
44
|
+
it { expect(actor.generate_task?).to be false }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/affect/emotion/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Client do
|
|
6
|
+
let(:client) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'responds to valence runner methods' do
|
|
9
|
+
expect(client).to respond_to(:evaluate_valence)
|
|
10
|
+
expect(client).to respond_to(:aggregate_valences)
|
|
11
|
+
expect(client).to respond_to(:modulate_attention)
|
|
12
|
+
expect(client).to respond_to(:compute_arousal)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'responds to gut runner methods' do
|
|
16
|
+
expect(client).to respond_to(:gut_instinct)
|
|
17
|
+
expect(client).to respond_to(:emotional_state)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'tracks domain counts for familiarity' do
|
|
21
|
+
client.track_domain('work')
|
|
22
|
+
client.track_domain('work')
|
|
23
|
+
client.track_domain('personal')
|
|
24
|
+
# Domain tracking improves familiarity scoring
|
|
25
|
+
result = client.evaluate_valence(signal: {}, domain: 'work')
|
|
26
|
+
expect(result[:valence][:familiarity]).to be >= 0.0
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'round-trips a full emotional evaluation cycle' do
|
|
30
|
+
# Evaluate multiple signals
|
|
31
|
+
v1 = client.evaluate_valence(signal: { urgency_hint: 0.8 }, source_type: :human_direct)
|
|
32
|
+
v2 = client.evaluate_valence(signal: { novelty_score: 0.9 }, source_type: :ambient)
|
|
33
|
+
|
|
34
|
+
# Aggregate
|
|
35
|
+
agg = client.aggregate_valences(valences: [v1[:valence], v2[:valence]])
|
|
36
|
+
expect(agg[:count]).to eq(2)
|
|
37
|
+
|
|
38
|
+
# Gut instinct
|
|
39
|
+
gut = client.gut_instinct(valences: [v1[:valence], v2[:valence]])
|
|
40
|
+
expect(gut[:signal]).to be_a(Symbol)
|
|
41
|
+
|
|
42
|
+
# State persists
|
|
43
|
+
state = client.emotional_state
|
|
44
|
+
expect(state[:momentum][:history_size]).to be >= 1
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Helpers::Baseline do
|
|
4
|
+
let(:baseline) { described_class.new }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'sets initial values for all dimensions' do
|
|
8
|
+
Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence::DIMENSIONS.each do |dim|
|
|
9
|
+
state = baseline.get(dim)
|
|
10
|
+
expect(state[:mean]).to eq(0.5)
|
|
11
|
+
expect(state[:stddev]).to eq(0.25)
|
|
12
|
+
expect(state[:count]).to eq(0)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#normalize' do
|
|
18
|
+
it 'normalizes a raw score against baseline' do
|
|
19
|
+
result = baseline.normalize(0.5, :urgency)
|
|
20
|
+
expect(result).to be_between(0.0, 1.0)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'returns higher value for scores above mean' do
|
|
24
|
+
low = baseline.normalize(0.3, :urgency)
|
|
25
|
+
high = baseline.normalize(0.9, :urgency)
|
|
26
|
+
expect(high).to be > low
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#update' do
|
|
31
|
+
it 'shifts mean toward observed values' do
|
|
32
|
+
original_mean = baseline.get(:urgency)[:mean]
|
|
33
|
+
10.times { baseline.update(:urgency, 0.9) }
|
|
34
|
+
expect(baseline.get(:urgency)[:mean]).to be > original_mean
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'increments count' do
|
|
38
|
+
3.times { baseline.update(:importance, 0.5) }
|
|
39
|
+
expect(baseline.get(:importance)[:count]).to eq(3)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'adapts slowly (alpha=0.05)' do
|
|
43
|
+
baseline.update(:urgency, 1.0)
|
|
44
|
+
# After one update, mean should barely move: 0.05*1.0 + 0.95*0.5 = 0.525
|
|
45
|
+
expect(baseline.get(:urgency)[:mean]).to be_within(0.001).of(0.525)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Helpers::Momentum do
|
|
4
|
+
let(:momentum) { described_class.new }
|
|
5
|
+
let(:valence_mod) { Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence }
|
|
6
|
+
|
|
7
|
+
describe '#initialize' do
|
|
8
|
+
it 'starts with zero state' do
|
|
9
|
+
state = momentum.emotional_state
|
|
10
|
+
expect(state[:arousal_ema]).to eq(0.0)
|
|
11
|
+
expect(state[:stability]).to eq(1.0)
|
|
12
|
+
expect(state[:history_size]).to eq(0)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#update' do
|
|
17
|
+
it 'updates EMA toward current values' do
|
|
18
|
+
v = valence_mod.new_valence(urgency: 0.8, importance: 0.7)
|
|
19
|
+
result = momentum.update(v, 0.6)
|
|
20
|
+
expect(result[:arousal_ema]).to be > 0.0
|
|
21
|
+
expect(result[:valence_ema][:urgency]).to be > 0.0
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'tracks history' do
|
|
25
|
+
v = valence_mod.new_valence(urgency: 0.5)
|
|
26
|
+
3.times { momentum.update(v, 0.5) }
|
|
27
|
+
expect(momentum.emotional_state[:history_size]).to eq(3)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'caps history at 100' do
|
|
31
|
+
v = valence_mod.new_valence
|
|
32
|
+
105.times { momentum.update(v, 0.1) }
|
|
33
|
+
expect(momentum.emotional_state[:history_size]).to eq(100)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'computes stability as inverse of emotional change' do
|
|
37
|
+
v_calm = valence_mod.new_valence(urgency: 0.1)
|
|
38
|
+
v_alarm = valence_mod.new_valence(urgency: 1.0, importance: 1.0, novelty: 1.0, familiarity: 1.0)
|
|
39
|
+
|
|
40
|
+
momentum.update(v_calm, 0.1)
|
|
41
|
+
result = momentum.update(v_alarm, 0.9)
|
|
42
|
+
expect(result[:stability]).to be < 1.0
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence do
|
|
4
|
+
describe '.new_valence' do
|
|
5
|
+
it 'creates a valence with defaults' do
|
|
6
|
+
v = described_class.new_valence
|
|
7
|
+
expect(v[:urgency]).to eq(0.0)
|
|
8
|
+
expect(v[:importance]).to eq(0.0)
|
|
9
|
+
expect(v[:novelty]).to eq(0.0)
|
|
10
|
+
expect(v[:familiarity]).to eq(0.0)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'creates a valence with custom values' do
|
|
14
|
+
v = described_class.new_valence(urgency: 0.8, importance: 0.6)
|
|
15
|
+
expect(v[:urgency]).to eq(0.8)
|
|
16
|
+
expect(v[:importance]).to eq(0.6)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'clamps values to [0, 1]' do
|
|
20
|
+
v = described_class.new_valence(urgency: 1.5, novelty: -0.3)
|
|
21
|
+
expect(v[:urgency]).to eq(1.0)
|
|
22
|
+
expect(v[:novelty]).to eq(0.0)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '.magnitude' do
|
|
27
|
+
it 'computes zero for zero valence' do
|
|
28
|
+
v = described_class.new_valence
|
|
29
|
+
expect(described_class.magnitude(v)).to eq(0.0)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'computes sqrt(4) for all-ones valence' do
|
|
33
|
+
v = described_class.new_valence(urgency: 1.0, importance: 1.0, novelty: 1.0, familiarity: 1.0)
|
|
34
|
+
expect(described_class.magnitude(v)).to be_within(0.001).of(2.0)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '.dominant_dimension' do
|
|
39
|
+
it 'returns the highest dimension' do
|
|
40
|
+
v = described_class.new_valence(urgency: 0.2, importance: 0.9, novelty: 0.1, familiarity: 0.3)
|
|
41
|
+
expect(described_class.dominant_dimension(v)).to eq(:importance)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '.aggregate' do
|
|
46
|
+
it 'returns zero valence for empty array' do
|
|
47
|
+
result = described_class.aggregate([])
|
|
48
|
+
expect(result[:urgency]).to eq(0.0)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'averages multiple valences' do
|
|
52
|
+
v1 = described_class.new_valence(urgency: 0.8, importance: 0.2)
|
|
53
|
+
v2 = described_class.new_valence(urgency: 0.4, importance: 0.6)
|
|
54
|
+
result = described_class.aggregate([v1, v2])
|
|
55
|
+
expect(result[:urgency]).to be_within(0.001).of(0.6)
|
|
56
|
+
expect(result[:importance]).to be_within(0.001).of(0.4)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '.compute_arousal' do
|
|
61
|
+
it 'returns 0 for empty valences' do
|
|
62
|
+
expect(described_class.compute_arousal([])).to eq(0.0)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'returns 1.0 for all-max valences' do
|
|
66
|
+
v = described_class.new_valence(urgency: 1.0, importance: 1.0, novelty: 1.0, familiarity: 1.0)
|
|
67
|
+
expect(described_class.compute_arousal([v])).to be_within(0.001).of(1.0)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'returns moderate arousal for mixed valences' do
|
|
71
|
+
v = described_class.new_valence(urgency: 0.5, importance: 0.5)
|
|
72
|
+
arousal = described_class.compute_arousal([v])
|
|
73
|
+
expect(arousal).to be > 0.0
|
|
74
|
+
expect(arousal).to be < 1.0
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '.modulate_salience' do
|
|
79
|
+
it 'boosts salience based on valence' do
|
|
80
|
+
v = described_class.new_valence(urgency: 0.8, importance: 0.6, novelty: 0.4)
|
|
81
|
+
modulated = described_class.modulate_salience(0.5, v)
|
|
82
|
+
expect(modulated).to be > 0.5
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'clamps at 1.0' do
|
|
86
|
+
v = described_class.new_valence(urgency: 1.0, importance: 1.0, novelty: 1.0)
|
|
87
|
+
modulated = described_class.modulate_salience(0.9, v)
|
|
88
|
+
expect(modulated).to eq(1.0)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/affect/emotion/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Runners::Gut do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Affect::Emotion::Client.new }
|
|
7
|
+
let(:valence_mod) { Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence }
|
|
8
|
+
|
|
9
|
+
describe '#gut_instinct' do
|
|
10
|
+
it 'returns neutral for empty valences' do
|
|
11
|
+
result = client.gut_instinct(valences: [])
|
|
12
|
+
expect(result[:signal]).to eq(:neutral)
|
|
13
|
+
expect(result[:confidence]).to eq(0.0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'returns alarm for high urgency + importance' do
|
|
17
|
+
v = valence_mod.new_valence(urgency: 0.9, importance: 0.9, novelty: 0.5, familiarity: 0.5)
|
|
18
|
+
result = client.gut_instinct(valences: [v])
|
|
19
|
+
expect(result[:signal]).to eq(:alarm)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns explore for high novelty + low familiarity' do
|
|
23
|
+
v = valence_mod.new_valence(urgency: 0.2, importance: 0.2, novelty: 0.9, familiarity: 0.1)
|
|
24
|
+
result = client.gut_instinct(valences: [v])
|
|
25
|
+
expect(result[:signal]).to eq(:explore)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'returns calm for low arousal' do
|
|
29
|
+
v = valence_mod.new_valence(urgency: 0.05, importance: 0.05, novelty: 0.05, familiarity: 0.05)
|
|
30
|
+
result = client.gut_instinct(valences: [v])
|
|
31
|
+
expect(result[:signal]).to eq(:calm)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'includes confidence and reliability' do
|
|
35
|
+
v = valence_mod.new_valence(urgency: 0.5)
|
|
36
|
+
result = client.gut_instinct(valences: [v], memory_signals: [1, 2, 3])
|
|
37
|
+
expect(result).to have_key(:confidence)
|
|
38
|
+
expect(result).to have_key(:reliable)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'increases confidence with more memory evidence' do
|
|
42
|
+
v = valence_mod.new_valence(urgency: 0.5)
|
|
43
|
+
low_evidence = client.gut_instinct(valences: [v], memory_signals: [])
|
|
44
|
+
high_evidence = client.gut_instinct(valences: [v], memory_signals: Array.new(10, 1))
|
|
45
|
+
expect(high_evidence[:confidence]).to be >= low_evidence[:confidence]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#emotional_state' do
|
|
50
|
+
it 'returns momentum and baseline state' do
|
|
51
|
+
state = client.emotional_state
|
|
52
|
+
expect(state).to have_key(:momentum)
|
|
53
|
+
expect(state).to have_key(:baseline)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#decay_momentum' do
|
|
58
|
+
it 'returns decayed: true' do
|
|
59
|
+
result = client.decay_momentum
|
|
60
|
+
expect(result[:decayed]).to be true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns a Float stability value' do
|
|
64
|
+
result = client.decay_momentum
|
|
65
|
+
expect(result[:stability]).to be_a(Float)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'returns stability within [0.0, 1.0]' do
|
|
69
|
+
result = client.decay_momentum
|
|
70
|
+
expect(result[:stability]).to be_between(0.0, 1.0)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/affect/emotion/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Emotion::Runners::Valence do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Affect::Emotion::Client.new }
|
|
7
|
+
|
|
8
|
+
describe '#evaluate_valence' do
|
|
9
|
+
it 'returns a valence with 4 dimensions' do
|
|
10
|
+
result = client.evaluate_valence(signal: { urgency_hint: 0.5 })
|
|
11
|
+
expect(result[:valence].keys).to contain_exactly(:urgency, :importance, :novelty, :familiarity)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'returns magnitude' do
|
|
15
|
+
result = client.evaluate_valence(signal: {})
|
|
16
|
+
expect(result[:magnitude]).to be >= 0.0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns dominant dimension' do
|
|
20
|
+
result = client.evaluate_valence(signal: { domain_weight: 0.9, impact_scope: 0.8, outcome_severity: 0.9 })
|
|
21
|
+
expect(result[:dominant_dimension]).to be_a(Symbol)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'responds to source type urgency' do
|
|
25
|
+
ambient = client.evaluate_valence(signal: {}, source_type: :ambient)
|
|
26
|
+
human = client.evaluate_valence(signal: {}, source_type: :human_direct)
|
|
27
|
+
expect(human[:valence][:urgency]).to be >= ambient[:valence][:urgency]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'responds to deadlines' do
|
|
31
|
+
no_deadline = client.evaluate_valence(signal: {})
|
|
32
|
+
with_deadline = client.evaluate_valence(signal: {}, deadline: Time.now.utc + 60)
|
|
33
|
+
expect(with_deadline[:valence][:urgency]).to be >= no_deadline[:valence][:urgency]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#aggregate_valences' do
|
|
38
|
+
it 'aggregates multiple valences' do
|
|
39
|
+
v = Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence
|
|
40
|
+
valences = [
|
|
41
|
+
v.new_valence(urgency: 0.8, importance: 0.2),
|
|
42
|
+
v.new_valence(urgency: 0.4, importance: 0.6)
|
|
43
|
+
]
|
|
44
|
+
result = client.aggregate_valences(valences: valences)
|
|
45
|
+
expect(result[:aggregate][:urgency]).to be_within(0.01).of(0.6)
|
|
46
|
+
expect(result[:count]).to eq(2)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '#modulate_attention' do
|
|
51
|
+
it 'boosts salience' do
|
|
52
|
+
v = Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence.new_valence(urgency: 0.8, importance: 0.7)
|
|
53
|
+
result = client.modulate_attention(base_salience: 0.5, valence: v)
|
|
54
|
+
expect(result[:modulated]).to be > result[:original]
|
|
55
|
+
expect(result[:boost]).to be > 0
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#compute_arousal' do
|
|
60
|
+
it 'computes arousal from valences' do
|
|
61
|
+
v = Legion::Extensions::Agentic::Affect::Emotion::Helpers::Valence
|
|
62
|
+
valences = [v.new_valence(urgency: 0.9, importance: 0.9)]
|
|
63
|
+
result = client.compute_arousal(valences: valences)
|
|
64
|
+
expect(result[:arousal]).to be > 0.0
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Empathy::Client do
|
|
4
|
+
it 'creates default model store' do
|
|
5
|
+
client = described_class.new
|
|
6
|
+
expect(client.model_store).to be_a(Legion::Extensions::Agentic::Affect::Empathy::Helpers::ModelStore)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'accepts injected model store' do
|
|
10
|
+
store = Legion::Extensions::Agentic::Affect::Empathy::Helpers::ModelStore.new
|
|
11
|
+
client = described_class.new(model_store: store)
|
|
12
|
+
expect(client.model_store).to equal(store)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'includes Empathy runner methods' do
|
|
16
|
+
client = described_class.new
|
|
17
|
+
expect(client).to respond_to(:observe_agent, :predict_reaction, :perspective_take,
|
|
18
|
+
:social_landscape, :empathy_stats)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Affect::Empathy::Helpers::Constants do
|
|
4
|
+
it 'defines 5 mental state dimensions' do
|
|
5
|
+
expect(described_class::MENTAL_STATE_DIMENSIONS.size).to eq(5)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'defines cooperation stances' do
|
|
9
|
+
expect(described_class::COOPERATION_STANCES).to include(:cooperative, :competitive, :neutral, :unknown)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'defines inferred emotions' do
|
|
13
|
+
expect(described_class::INFERRED_EMOTIONS).to include(:calm, :stressed, :curious, :unknown)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'defines prediction thresholds in order' do
|
|
17
|
+
expect(described_class::PREDICTION_UNCERTAIN).to be < described_class::PREDICTION_CONFIDENT
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'sets MAX_TRACKED_AGENTS to 100' do
|
|
21
|
+
expect(described_class::MAX_TRACKED_AGENTS).to eq(100)
|
|
22
|
+
end
|
|
23
|
+
end
|