lex-agentic-affect 0.1.5 → 0.1.6
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/lib/legion/extensions/agentic/affect/appraisal/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/appraisal/runners/appraisal.rb +18 -16
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/cognitive_empathy/runners/cognitive_empathy.rb +3 -1
- data/lib/legion/extensions/agentic/affect/contagion/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/contagion/runners/cognitive_contagion.rb +24 -24
- data/lib/legion/extensions/agentic/affect/defusion/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/defusion/runners/cognitive_defusion.rb +21 -21
- data/lib/legion/extensions/agentic/affect/emotion/actors/momentum_decay.rb +1 -1
- data/lib/legion/extensions/agentic/affect/emotion/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/emotion/runners/gut.rb +7 -7
- data/lib/legion/extensions/agentic/affect/emotion/runners/valence.rb +10 -10
- data/lib/legion/extensions/agentic/affect/empathy/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/empathy/runners/empathy.rb +14 -14
- data/lib/legion/extensions/agentic/affect/fatigue/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/fatigue/runners/fatigue.rb +9 -9
- data/lib/legion/extensions/agentic/affect/flow/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/flow/runners/flow.rb +8 -8
- data/lib/legion/extensions/agentic/affect/interoception/actors/decay.rb +1 -1
- data/lib/legion/extensions/agentic/affect/interoception/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/interoception/runners/interoception.rb +12 -12
- data/lib/legion/extensions/agentic/affect/mood/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/mood/runners/mood.rb +7 -7
- data/lib/legion/extensions/agentic/affect/motivation/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/motivation/runners/motivation.rb +13 -13
- data/lib/legion/extensions/agentic/affect/reappraisal/actors/auto_regulate.rb +1 -1
- data/lib/legion/extensions/agentic/affect/reappraisal/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/reappraisal/helpers/llm_enhancer.rb +4 -4
- data/lib/legion/extensions/agentic/affect/reappraisal/runners/cognitive_reappraisal.rb +17 -17
- data/lib/legion/extensions/agentic/affect/regulation/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/regulation/runners/emotional_regulation.rb +12 -12
- data/lib/legion/extensions/agentic/affect/resilience/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/resilience/runners/resilience.rb +10 -10
- data/lib/legion/extensions/agentic/affect/resonance/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/resonance/helpers/resonance_engine.rb +10 -6
- data/lib/legion/extensions/agentic/affect/resonance/runners/cognitive_resonance.rb +12 -12
- data/lib/legion/extensions/agentic/affect/reward/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/reward/runners/reward.rb +10 -10
- data/lib/legion/extensions/agentic/affect/somatic_marker/actors/decay.rb +1 -1
- data/lib/legion/extensions/agentic/affect/somatic_marker/client.rb +1 -0
- data/lib/legion/extensions/agentic/affect/somatic_marker/runners/somatic_marker.rb +31 -31
- data/lib/legion/extensions/agentic/affect/version.rb +1 -1
- data/lib/legion/extensions/agentic/affect.rb +1 -1
- data/spec/legion/extensions/agentic/affect/somatic_marker/helpers/marker_store_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3edfb8ca48c97428f04fd913693fcffb129c1ee5bb8779be2dbd61ffeeeeed6
|
|
4
|
+
data.tar.gz: 6443631b15f56be9897948a5149912af86d203e81cc893ad86fe6e8d258e2122
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d28e2998e7ae2f15c19754565e8bb2fa92b67d4a9727f9e9d232cbff5c39e235570da1aa2e306363a1cc6a15f7476794bdc12bcebe7690efb0e1cc5819bc3926
|
|
7
|
+
data.tar.gz: 8d6c801d3769cb4b10db6db28eb62e81726c8213981e1fb5d2c92b61e9b625c714c7ce48f39928315e22cd406601992a165ce9db053d1f9b356c3b081bc13b74
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -7,76 +7,78 @@ module Legion
|
|
|
7
7
|
module Appraisal
|
|
8
8
|
module Runners
|
|
9
9
|
module Appraisal
|
|
10
|
+
extend self
|
|
11
|
+
|
|
10
12
|
def appraise_event(event:, primary:, secondary:, domain: nil, **)
|
|
11
|
-
|
|
13
|
+
log.debug("[lex-appraisal] appraise_event event=#{event} domain=#{domain}")
|
|
12
14
|
record = engine.appraise(event: event, primary: primary, secondary: secondary, domain: domain)
|
|
13
15
|
{ success: true, appraisal: record.to_h }
|
|
14
16
|
rescue StandardError => e
|
|
15
|
-
|
|
17
|
+
log.error("[lex-appraisal] appraise_event error: #{e.message}")
|
|
16
18
|
{ success: false, error: e.message }
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def reappraise_event(appraisal_id:, new_primary:, new_secondary:, **)
|
|
20
|
-
|
|
22
|
+
log.debug("[lex-appraisal] reappraise_event id=#{appraisal_id}")
|
|
21
23
|
record = engine.reappraise(appraisal_id: appraisal_id, new_primary: new_primary,
|
|
22
24
|
new_secondary: new_secondary)
|
|
23
25
|
return { success: false, error: 'appraisal not found' } unless record
|
|
24
26
|
|
|
25
27
|
{ success: true, appraisal: record.to_h }
|
|
26
28
|
rescue StandardError => e
|
|
27
|
-
|
|
29
|
+
log.error("[lex-appraisal] reappraise_event error: #{e.message}")
|
|
28
30
|
{ success: false, error: e.message }
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def select_coping_strategy(appraisal_id:, coping_type:, **)
|
|
32
|
-
|
|
34
|
+
log.debug("[lex-appraisal] select_coping appraisal_id=#{appraisal_id}")
|
|
33
35
|
record = engine.select_coping(appraisal_id: appraisal_id, coping_type: coping_type)
|
|
34
36
|
return { success: false, error: 'appraisal not found' } unless record
|
|
35
37
|
|
|
36
38
|
{ success: true, appraisal: record.to_h }
|
|
37
39
|
rescue StandardError => e
|
|
38
|
-
|
|
40
|
+
log.error("[lex-appraisal] select_coping error: #{e.message}")
|
|
39
41
|
{ success: false, error: e.message }
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def add_coping_strategy(name:, coping_type:, effectiveness:, **)
|
|
43
|
-
|
|
45
|
+
log.debug("[lex-appraisal] add_coping_strategy name=#{name}")
|
|
44
46
|
added = engine.add_coping_strategy(name: name, coping_type: coping_type, effectiveness: effectiveness)
|
|
45
47
|
{ success: added, name: name, coping_type: coping_type }
|
|
46
48
|
rescue StandardError => e
|
|
47
|
-
|
|
49
|
+
log.error("[lex-appraisal] add_coping_strategy error: #{e.message}")
|
|
48
50
|
{ success: false, error: e.message }
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def evaluate_coping(appraisal_id:, **)
|
|
52
|
-
|
|
54
|
+
log.debug("[lex-appraisal] evaluate_coping id=#{appraisal_id}")
|
|
53
55
|
result = engine.evaluate_coping(appraisal_id: appraisal_id)
|
|
54
56
|
{ success: true }.merge(result)
|
|
55
57
|
rescue StandardError => e
|
|
56
|
-
|
|
58
|
+
log.error("[lex-appraisal] evaluate_coping error: #{e.message}")
|
|
57
59
|
{ success: false, error: e.message }
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
def emotional_pattern(**)
|
|
61
|
-
|
|
63
|
+
log.debug('[lex-appraisal] emotional_pattern')
|
|
62
64
|
pattern = engine.emotional_pattern
|
|
63
65
|
{ success: true, pattern: pattern }
|
|
64
66
|
rescue StandardError => e
|
|
65
|
-
|
|
67
|
+
log.error("[lex-appraisal] emotional_pattern error: #{e.message}")
|
|
66
68
|
{ success: false, error: e.message }
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
def update_appraisal(**)
|
|
70
|
-
|
|
72
|
+
log.debug('[lex-appraisal] update_appraisal (decay cycle)')
|
|
71
73
|
engine.decay_all
|
|
72
74
|
{ success: true }
|
|
73
75
|
rescue StandardError => e
|
|
74
|
-
|
|
76
|
+
log.error("[lex-appraisal] update_appraisal error: #{e.message}")
|
|
75
77
|
{ success: false, error: e.message }
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
def appraisal_stats(**)
|
|
79
|
-
|
|
81
|
+
log.debug('[lex-appraisal] appraisal_stats')
|
|
80
82
|
data = engine.to_h
|
|
81
83
|
unresolved = engine.unresolved.size
|
|
82
84
|
{
|
|
@@ -87,7 +89,7 @@ module Legion
|
|
|
87
89
|
pattern: engine.emotional_pattern
|
|
88
90
|
}
|
|
89
91
|
rescue StandardError => e
|
|
90
|
-
|
|
92
|
+
log.error("[lex-appraisal] appraisal_stats error: #{e.message}")
|
|
91
93
|
{ success: false, error: e.message }
|
|
92
94
|
end
|
|
93
95
|
|
|
@@ -81,7 +81,9 @@ module Legion
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def accuracy_label(accuracy)
|
|
84
|
-
ACCURACY_LABELS.each
|
|
84
|
+
ACCURACY_LABELS.each do |range, lbl|
|
|
85
|
+
return lbl if range.cover?(accuracy) # rubocop:disable Legion/Extension/RunnerReturnHash
|
|
86
|
+
end
|
|
85
87
|
:blind
|
|
86
88
|
end
|
|
87
89
|
end
|
|
@@ -7,20 +7,20 @@ module Legion
|
|
|
7
7
|
module Contagion
|
|
8
8
|
module Runners
|
|
9
9
|
module CognitiveContagion
|
|
10
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
12
12
|
|
|
13
13
|
def create_meme(label:, contagion_type: :cognitive, virulence: nil, **)
|
|
14
14
|
v = virulence || Helpers::Constants::DEFAULT_VIRULENCE
|
|
15
15
|
result = engine.create_meme(label: label, contagion_type: contagion_type, virulence: v)
|
|
16
16
|
|
|
17
17
|
if result.is_a?(Hash) && result[:error]
|
|
18
|
-
|
|
19
|
-
return result
|
|
18
|
+
log.warn("[cognitive_contagion] create_meme failed: #{result[:error]}")
|
|
19
|
+
return result # rubocop:disable Legion/Extension/RunnerReturnHash
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
log.info("[cognitive_contagion] meme created: id=#{result.id} label=#{label} " \
|
|
23
|
+
"virulence=#{result.virulence} type=#{contagion_type}")
|
|
24
24
|
result.to_h
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -29,11 +29,11 @@ module Legion
|
|
|
29
29
|
result = engine.register_agent(agent_id: agent_id, resistance: r)
|
|
30
30
|
|
|
31
31
|
if result.is_a?(Hash) && result[:error]
|
|
32
|
-
|
|
33
|
-
return result
|
|
32
|
+
log.warn("[cognitive_contagion] register_agent failed: #{result[:error]}")
|
|
33
|
+
return result # rubocop:disable Legion/Extension/RunnerReturnHash
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
log.debug("[cognitive_contagion] agent registered: id=#{agent_id} resistance=#{r}")
|
|
37
37
|
result
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -43,15 +43,15 @@ module Legion
|
|
|
43
43
|
source_agent_id: source_agent_id,
|
|
44
44
|
target_agent_id: target_agent_id
|
|
45
45
|
)
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
log.debug("[cognitive_contagion] transmission: meme=#{meme_id} " \
|
|
47
|
+
"#{source_agent_id}->#{target_agent_id} transmitted=#{result[:transmitted]}")
|
|
48
48
|
result
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def recover_agent(meme_id:, agent_id:, **)
|
|
52
52
|
result = engine.recover_agent(meme_id: meme_id, agent_id: agent_id)
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
log.debug("[cognitive_contagion] recover: meme=#{meme_id} agent=#{agent_id} " \
|
|
54
|
+
"result=#{result[:result]}")
|
|
55
55
|
result
|
|
56
56
|
end
|
|
57
57
|
|
|
@@ -60,51 +60,51 @@ module Legion
|
|
|
60
60
|
return { infected: false, reason: :meme_not_found } unless meme
|
|
61
61
|
|
|
62
62
|
result = meme.infect!(agent_id: agent_id)
|
|
63
|
-
|
|
63
|
+
log.debug("[cognitive_contagion] infect_agent: meme=#{meme_id} agent=#{agent_id} result=#{result}")
|
|
64
64
|
{ infected: result == :infected, agent_id: agent_id, meme_id: meme_id, result: result }
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def immunize_agent(meme_id:, agent_id:, **)
|
|
68
68
|
result = engine.immunize_agent(meme_id: meme_id, agent_id: agent_id)
|
|
69
|
-
|
|
69
|
+
log.debug("[cognitive_contagion] immunize: meme=#{meme_id} agent=#{agent_id}")
|
|
70
70
|
result
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def spread_step(meme_id:, **)
|
|
74
74
|
result = engine.spread_step(meme_id: meme_id)
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
log.info("[cognitive_contagion] spread_step: meme=#{meme_id} " \
|
|
76
|
+
"transmissions=#{result[:transmissions]} recoveries=#{result[:recoveries]}")
|
|
77
77
|
result
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def epidemic_report(meme_id:, **)
|
|
81
81
|
result = engine.epidemic_report(meme_id: meme_id)
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
log.debug("[cognitive_contagion] epidemic_report: meme=#{meme_id} " \
|
|
83
|
+
"infected=#{result[:infected]} virulence_label=#{result[:virulence_label]}")
|
|
84
84
|
result
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def most_viral(limit: 5, **)
|
|
88
88
|
results = engine.most_viral(limit: limit)
|
|
89
|
-
|
|
89
|
+
log.debug("[cognitive_contagion] most_viral: limit=#{limit} count=#{results.size}")
|
|
90
90
|
{ memes: results, count: results.size }
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def agent_status(agent_id:, meme_id:, **)
|
|
94
94
|
result = engine.agent_status(agent_id: agent_id, meme_id: meme_id)
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
log.debug("[cognitive_contagion] agent_status: agent=#{agent_id} " \
|
|
96
|
+
"meme=#{meme_id} status=#{result[:status]}")
|
|
97
97
|
result
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def susceptible_agents(meme_id:, **)
|
|
101
101
|
agents = engine.susceptible_agents(meme_id: meme_id)
|
|
102
|
-
|
|
102
|
+
log.debug("[cognitive_contagion] susceptible_agents: meme=#{meme_id} count=#{agents.size}")
|
|
103
103
|
{ agents: agents, count: agents.size, meme_id: meme_id }
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def contagion_status(**)
|
|
107
|
-
|
|
107
|
+
log.debug('[cognitive_contagion] contagion_status requested')
|
|
108
108
|
summary = engine.to_h.slice(:meme_count, :agent_count)
|
|
109
109
|
summary.merge(contagion_types: Helpers::Constants::CONTAGION_TYPES,
|
|
110
110
|
max_agents: Helpers::Constants::MAX_AGENTS,
|
|
@@ -7,16 +7,16 @@ module Legion
|
|
|
7
7
|
module Defusion
|
|
8
8
|
module Runners
|
|
9
9
|
module CognitiveDefusion
|
|
10
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
12
12
|
|
|
13
13
|
def register_thought(content:, thought_type:, belief_strength: 0.5, engine: nil, **)
|
|
14
14
|
eng = engine || defusion_engine
|
|
15
15
|
result = eng.register_thought(content: content, thought_type: thought_type, belief_strength: belief_strength)
|
|
16
16
|
return { success: false, **result } if result[:error]
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
log.debug("[cognitive_defusion] registered thought type=#{thought_type} " \
|
|
19
|
+
"belief=#{belief_strength.round(2)} id=#{result[:thought_id]}")
|
|
20
20
|
{ success: true, **result }
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -25,8 +25,8 @@ module Legion
|
|
|
25
25
|
result = eng.apply_defusion(thought_id: thought_id, technique: technique)
|
|
26
26
|
return { success: false, **result } if result[:error]
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
log.debug("[cognitive_defusion] defusion applied technique=#{technique} " \
|
|
29
|
+
"reduction=#{result[:reduction]&.round(4)} fusion=#{result[:after]&.round(4)}")
|
|
30
30
|
result
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -35,8 +35,8 @@ module Legion
|
|
|
35
35
|
result = eng.apply_all_techniques(thought_id: thought_id)
|
|
36
36
|
return { success: false, **result } if result[:error]
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
log.debug("[cognitive_defusion] all techniques applied thought_id=#{thought_id} " \
|
|
39
|
+
"final_fusion=#{result[:final_fusion]&.round(4)}")
|
|
40
40
|
{ success: true, **result }
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -45,8 +45,8 @@ module Legion
|
|
|
45
45
|
result = eng.visit_thought(thought_id: thought_id)
|
|
46
46
|
return { success: false, **result } if result[:error]
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
log.debug("[cognitive_defusion] thought visited count=#{result[:visit_count]} " \
|
|
49
|
+
"ruminating=#{result[:ruminating]}")
|
|
50
50
|
{ success: true, **result }
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -56,36 +56,36 @@ module Legion
|
|
|
56
56
|
return { success: false, error: :thought_not_found } unless thought
|
|
57
57
|
|
|
58
58
|
result = thought.fuse!
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
log.debug("[cognitive_defusion] thought fused before=#{result[:before].round(4)} " \
|
|
60
|
+
"after=#{result[:after].round(4)}")
|
|
61
61
|
{ success: true, thought_id: thought_id, before: result[:before], after: result[:after], enmeshed: thought.enmeshed? }
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def enmeshed_thoughts(engine: nil, **)
|
|
65
65
|
eng = engine || defusion_engine
|
|
66
66
|
thoughts = eng.enmeshed_thoughts.map(&:to_h)
|
|
67
|
-
|
|
67
|
+
log.debug("[cognitive_defusion] enmeshed thoughts count=#{thoughts.size}")
|
|
68
68
|
{ success: true, count: thoughts.size, thoughts: thoughts }
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def defused_thoughts(engine: nil, **)
|
|
72
72
|
eng = engine || defusion_engine
|
|
73
73
|
thoughts = eng.defused_thoughts.map(&:to_h)
|
|
74
|
-
|
|
74
|
+
log.debug("[cognitive_defusion] defused thoughts count=#{thoughts.size}")
|
|
75
75
|
{ success: true, count: thoughts.size, thoughts: thoughts }
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def ruminating_thoughts(engine: nil, **)
|
|
79
79
|
eng = engine || defusion_engine
|
|
80
80
|
thoughts = eng.ruminating_thoughts.map(&:to_h)
|
|
81
|
-
|
|
81
|
+
log.debug("[cognitive_defusion] ruminating thoughts count=#{thoughts.size}")
|
|
82
82
|
{ success: true, count: thoughts.size, thoughts: thoughts }
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def most_fused(limit: 5, engine: nil, **)
|
|
86
86
|
eng = engine || defusion_engine
|
|
87
87
|
thoughts = eng.most_fused(limit: limit).map(&:to_h)
|
|
88
|
-
|
|
88
|
+
log.debug("[cognitive_defusion] most fused count=#{thoughts.size}")
|
|
89
89
|
{ success: true, count: thoughts.size, thoughts: thoughts }
|
|
90
90
|
end
|
|
91
91
|
|
|
@@ -94,22 +94,22 @@ module Legion
|
|
|
94
94
|
result = eng.recommend_technique(thought_id: thought_id)
|
|
95
95
|
return { success: false, **result } if result[:error]
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
log.debug("[cognitive_defusion] technique recommended=#{result[:technique]} " \
|
|
98
|
+
"for type=#{result[:thought_type]}")
|
|
99
99
|
{ success: true, **result }
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def defusion_report(engine: nil, **)
|
|
103
103
|
eng = engine || defusion_engine
|
|
104
104
|
report = eng.defusion_report
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
log.debug("[cognitive_defusion] report: total=#{report[:total_thoughts]} " \
|
|
106
|
+
"enmeshed=#{report[:enmeshed_count]} avg_fusion=#{report[:average_fusion].round(4)}")
|
|
107
107
|
{ success: true, **report }
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
def defusion_state(engine: nil, **)
|
|
111
111
|
eng = engine || defusion_engine
|
|
112
|
-
|
|
112
|
+
log.debug('[cognitive_defusion] state queried')
|
|
113
113
|
{ success: true, **eng.to_h }
|
|
114
114
|
end
|
|
115
115
|
|
|
@@ -8,7 +8,7 @@ module Legion
|
|
|
8
8
|
module Affect
|
|
9
9
|
module Emotion
|
|
10
10
|
module Actor
|
|
11
|
-
class MomentumDecay < Legion::Extensions::Actors::Every
|
|
11
|
+
class MomentumDecay < Legion::Extensions::Actors::Every # rubocop:disable Legion/Extension/EveryActorRequiresTime
|
|
12
12
|
def runner_class
|
|
13
13
|
Legion::Extensions::Agentic::Affect::Emotion::Runners::Gut
|
|
14
14
|
end
|
|
@@ -7,8 +7,8 @@ module Legion
|
|
|
7
7
|
module Emotion
|
|
8
8
|
module Runners
|
|
9
9
|
module Gut
|
|
10
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
12
12
|
|
|
13
13
|
def gut_instinct(valences:, memory_signals: [], confidence_threshold: 0.5, **)
|
|
14
14
|
return { signal: :neutral, confidence: 0.0, basis: :insufficient_data } if valences.empty?
|
|
@@ -20,8 +20,8 @@ module Legion
|
|
|
20
20
|
signal = determine_signal(aggregate, arousal)
|
|
21
21
|
confidence = compute_confidence(valences, memory_signals)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
log.debug("[emotion] gut instinct: signal=#{signal} confidence=#{confidence.round(2)} " \
|
|
24
|
+
"arousal=#{arousal.round(2)} dominant=#{dominant} reliable=#{confidence >= confidence_threshold}")
|
|
25
25
|
|
|
26
26
|
result = {
|
|
27
27
|
signal: signal,
|
|
@@ -44,7 +44,7 @@ module Legion
|
|
|
44
44
|
momentum.update(neutral, 0.5)
|
|
45
45
|
stability = momentum.stability
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
log.debug("[emotion] momentum decay: stability=#{stability.round(2)}")
|
|
48
48
|
|
|
49
49
|
{ decayed: true, stability: stability }
|
|
50
50
|
end
|
|
@@ -52,7 +52,7 @@ module Legion
|
|
|
52
52
|
def emotional_state(**)
|
|
53
53
|
momentum = emotion_momentum
|
|
54
54
|
state = momentum.emotional_state
|
|
55
|
-
|
|
55
|
+
log.debug("[emotion] state query: stability=#{state[:stability]&.round(2)}")
|
|
56
56
|
{
|
|
57
57
|
momentum: state,
|
|
58
58
|
baseline: emotion_baseline.dimensions
|
|
@@ -82,7 +82,7 @@ module Legion
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def compute_confidence(valences, memory_signals)
|
|
85
|
-
return 0.0 if valences.empty?
|
|
85
|
+
return 0.0 if valences.empty? # rubocop:disable Legion/Extension/RunnerReturnHash
|
|
86
86
|
|
|
87
87
|
magnitudes = valences.map { |v| Helpers::Valence.magnitude(v) }
|
|
88
88
|
mean_mag = magnitudes.sum / magnitudes.size
|
|
@@ -7,8 +7,8 @@ module Legion
|
|
|
7
7
|
module Emotion
|
|
8
8
|
module Runners
|
|
9
9
|
module Valence
|
|
10
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
12
12
|
|
|
13
13
|
def evaluate_valence(signal:, source_type: :ambient, deadline: nil, domain: nil, **)
|
|
14
14
|
baseline = emotion_baseline
|
|
@@ -34,9 +34,9 @@ module Legion
|
|
|
34
34
|
|
|
35
35
|
magnitude = Helpers::Valence.magnitude(valence)
|
|
36
36
|
dominant = Helpers::Valence.dominant_dimension(valence)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
log.debug("[emotion] valence: source=#{source_type} magnitude=#{magnitude.round(2)} dominant=#{dominant} " \
|
|
38
|
+
"u=#{valence[:urgency].round(2)} i=#{valence[:importance].round(2)} " \
|
|
39
|
+
"n=#{valence[:novelty].round(2)} f=#{valence[:familiarity].round(2)}")
|
|
40
40
|
|
|
41
41
|
{
|
|
42
42
|
valence: valence,
|
|
@@ -50,7 +50,7 @@ module Legion
|
|
|
50
50
|
arousal = Helpers::Valence.compute_arousal(valences)
|
|
51
51
|
dominant = Helpers::Valence.dominant_dimension(aggregated)
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
log.debug("[emotion] aggregate: count=#{valences.size} arousal=#{arousal.round(2)} dominant=#{dominant}")
|
|
54
54
|
{
|
|
55
55
|
aggregate: aggregated,
|
|
56
56
|
arousal: arousal,
|
|
@@ -62,13 +62,13 @@ module Legion
|
|
|
62
62
|
def modulate_attention(base_salience:, valence:, **)
|
|
63
63
|
modulated = Helpers::Valence.modulate_salience(base_salience, valence)
|
|
64
64
|
boost = modulated - base_salience
|
|
65
|
-
|
|
65
|
+
log.debug("[emotion] attention modulation: base=#{base_salience.round(2)} modulated=#{modulated.round(2)} boost=#{boost.round(2)}")
|
|
66
66
|
{ original: base_salience, modulated: modulated, boost: boost }
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
def compute_arousal(valences:, **)
|
|
70
70
|
arousal = Helpers::Valence.compute_arousal(valences)
|
|
71
|
-
|
|
71
|
+
log.debug("[emotion] arousal=#{arousal.round(2)} from #{valences.size} valences")
|
|
72
72
|
{ arousal: arousal }
|
|
73
73
|
end
|
|
74
74
|
|
|
@@ -78,8 +78,8 @@ module Legion
|
|
|
78
78
|
outcome_severity: boost, novelty_score: 0.3 }
|
|
79
79
|
result = evaluate_valence(signal: signal, source_type: :mesh_priority)
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
log.info("[emotion] knowledge_vulnerability urgency raised: domains=#{Array(domains_at_risk).join(',')} " \
|
|
82
|
+
"severity=#{severity} boost=#{boost.round(2)} urgency=#{result[:valence][:urgency].round(2)}")
|
|
83
83
|
|
|
84
84
|
result.merge(event: :knowledge_vulnerability, domains_at_risk: Array(domains_at_risk), urgency_boost: boost)
|
|
85
85
|
end
|