lex-agentic-inference 0.1.1 → 0.1.2

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +2 -2
  4. data/lex-agentic-inference.gemspec +8 -0
  5. data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +19 -19
  6. data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +6 -6
  7. data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +17 -14
  8. data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +10 -10
  9. data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +14 -14
  10. data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +13 -13
  11. data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +14 -14
  12. data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +16 -16
  13. data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +11 -11
  14. data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +29 -29
  15. data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +17 -17
  16. data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +12 -12
  17. data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +16 -16
  18. data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +10 -10
  19. data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +11 -11
  20. data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +2 -0
  21. data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +13 -13
  22. data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +16 -16
  23. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +2 -0
  24. data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +12 -12
  25. data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +9 -9
  26. data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +13 -13
  27. data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +11 -11
  28. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +5 -3
  29. data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +4 -4
  30. data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +8 -8
  31. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +14 -14
  32. data/lib/legion/extensions/agentic/inference/version.rb +1 -1
  33. data/spec/spec_helper.rb +21 -23
  34. metadata +99 -1
@@ -27,12 +27,12 @@ module Legion
27
27
  )
28
28
 
29
29
  if result.is_a?(Hash) && result[:error]
30
- Legion::Logging.warn "[cognitive_gravity] create_attractor failed: #{result[:error]}"
30
+ log.warn "[cognitive_gravity] create_attractor failed: #{result[:error]}"
31
31
  return { success: false, **result }
32
32
  end
33
33
 
34
- Legion::Logging.debug "[cognitive_gravity] attractor created id=#{result.id[0..7]} " \
35
- "domain=#{domain} mass=#{mass}"
34
+ log.debug "[cognitive_gravity] attractor created id=#{result.id[0..7]} " \
35
+ "domain=#{domain} mass=#{mass}"
36
36
  { success: true, attractor: result.to_h }
37
37
  end
38
38
 
@@ -47,20 +47,20 @@ module Legion
47
47
  )
48
48
 
49
49
  if result.is_a?(Hash) && result[:error]
50
- Legion::Logging.warn "[cognitive_gravity] add_thought failed: #{result[:error]}"
50
+ log.warn "[cognitive_gravity] add_thought failed: #{result[:error]}"
51
51
  return { success: false, **result }
52
52
  end
53
53
 
54
- Legion::Logging.debug "[cognitive_gravity] thought added id=#{result.id[0..7]} " \
55
- "attractor=#{attractor_id[0..7]} distance=#{orbital_distance}"
54
+ log.debug "[cognitive_gravity] thought added id=#{result.id[0..7]} " \
55
+ "attractor=#{attractor_id[0..7]} distance=#{orbital_distance}"
56
56
  { success: true, thought: result.to_h }
57
57
  end
58
58
 
59
59
  def tick_gravity(engine: nil, **)
60
60
  eng = engine || gravity_engine
61
61
  result = eng.simulate_tick
62
- Legion::Logging.debug "[cognitive_gravity] tick: captures=#{result[:captures].size} " \
63
- "escapes=#{result[:escapes].size}"
62
+ log.debug "[cognitive_gravity] tick: captures=#{result[:captures].size} " \
63
+ "escapes=#{result[:escapes].size}"
64
64
  { success: true, **result }
65
65
  end
66
66
 
@@ -69,11 +69,11 @@ module Legion
69
69
  result = eng.accrete_attractor(attractor_id, amount: amount)
70
70
 
71
71
  if result[:error]
72
- Legion::Logging.warn "[cognitive_gravity] accrete failed: #{result[:error]}"
72
+ log.warn "[cognitive_gravity] accrete failed: #{result[:error]}"
73
73
  return { success: false, **result }
74
74
  end
75
75
 
76
- Legion::Logging.debug "[cognitive_gravity] accreted id=#{attractor_id[0..7]} mass=#{result[:mass]}"
76
+ log.debug "[cognitive_gravity] accreted id=#{attractor_id[0..7]} mass=#{result[:mass]}"
77
77
  { success: true, **result }
78
78
  end
79
79
 
@@ -82,19 +82,19 @@ module Legion
82
82
  result = eng.erode_attractor(attractor_id, amount: amount)
83
83
 
84
84
  if result[:error]
85
- Legion::Logging.warn "[cognitive_gravity] erode failed: #{result[:error]}"
85
+ log.warn "[cognitive_gravity] erode failed: #{result[:error]}"
86
86
  return { success: false, **result }
87
87
  end
88
88
 
89
- Legion::Logging.debug "[cognitive_gravity] eroded id=#{attractor_id[0..7]} " \
90
- "mass=#{result[:mass]} collapsed=#{result[:collapsed]}"
89
+ log.debug "[cognitive_gravity] eroded id=#{attractor_id[0..7]} " \
90
+ "mass=#{result[:mass]} collapsed=#{result[:collapsed]}"
91
91
  { success: true, **result }
92
92
  end
93
93
 
94
94
  def strongest_attractors(limit: 5, engine: nil, **)
95
95
  eng = engine || gravity_engine
96
96
  attractors = eng.strongest_attractors(limit: limit)
97
- Legion::Logging.debug "[cognitive_gravity] strongest_attractors count=#{attractors.size}"
97
+ log.debug "[cognitive_gravity] strongest_attractors count=#{attractors.size}"
98
98
  { success: true, attractors: attractors.map(&:to_h), count: attractors.size }
99
99
  end
100
100
 
@@ -113,8 +113,8 @@ module Legion
113
113
  def gravity_report(engine: nil, **)
114
114
  eng = engine || gravity_engine
115
115
  report = eng.gravity_report
116
- Legion::Logging.debug "[cognitive_gravity] report: attractors=#{report[:total_attractors]} " \
117
- "orbiting=#{report[:total_orbiting]} supermassive=#{report[:supermassive_count]}"
116
+ log.debug "[cognitive_gravity] report: attractors=#{report[:total_attractors]} " \
117
+ "orbiting=#{report[:total_orbiting]} supermassive=#{report[:supermassive_count]}"
118
118
  { success: true, report: report }
119
119
  end
120
120
 
@@ -12,7 +12,7 @@ module Legion
12
12
 
13
13
  def get_horizon(**)
14
14
  report = horizon_engine.horizon_report
15
- Legion::Logging.debug "[cognitive_horizon] get_horizon: effective=#{report[:effective_horizon].round(2)} construal=#{report[:construal_label]}"
15
+ log.debug "[cognitive_horizon] get_horizon: effective=#{report[:effective_horizon].round(2)} construal=#{report[:construal_label]}"
16
16
  { found: true, horizon: report }
17
17
  end
18
18
 
@@ -20,7 +20,7 @@ module Legion
20
20
  amt = amount || Helpers::Constants::HORIZON_EXPAND
21
21
  before = horizon_engine.current_horizon
22
22
  after = horizon_engine.expand_horizon!(amount: amt)
23
- Legion::Logging.info "[cognitive_horizon] expand: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
23
+ log.info "[cognitive_horizon] expand: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
24
24
  { expanded: true, before: before.round(10), after: after.round(10), amount: amt }
25
25
  end
26
26
 
@@ -28,14 +28,14 @@ module Legion
28
28
  amt = amount || Helpers::Constants::HORIZON_CONTRACT
29
29
  before = horizon_engine.current_horizon
30
30
  after = horizon_engine.contract_horizon!(amount: amt)
31
- Legion::Logging.info "[cognitive_horizon] contract: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
31
+ log.info "[cognitive_horizon] contract: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
32
32
  { contracted: true, before: before.round(10), after: after.round(10), amount: amt }
33
33
  end
34
34
 
35
35
  def apply_stress(level:, **)
36
36
  before = horizon_engine.current_horizon
37
37
  after = horizon_engine.apply_stress!(level)
38
- Legion::Logging.info "[cognitive_horizon] stress applied: level=#{level} horizon #{before.round(2)} -> #{after.round(2)}"
38
+ log.info "[cognitive_horizon] stress applied: level=#{level} horizon #{before.round(2)} -> #{after.round(2)}"
39
39
  {
40
40
  stress_applied: true,
41
41
  stress_level: level,
@@ -49,7 +49,7 @@ module Legion
49
49
  before = horizon_engine.stress_level
50
50
  horizon_engine.relieve_stress!(amount: amt)
51
51
  after = horizon_engine.stress_level
52
- Legion::Logging.debug "[cognitive_horizon] relieve_stress: #{before.round(2)} -> #{after.round(2)}"
52
+ log.debug "[cognitive_horizon] relieve_stress: #{before.round(2)} -> #{after.round(2)}"
53
53
  { relieved: true, before: before.round(10), after: after.round(10), amount: amt }
54
54
  end
55
55
 
@@ -61,31 +61,31 @@ module Legion
61
61
  confidence: confidence
62
62
  )
63
63
  msg = "[cognitive_horizon] add_projection: id=#{proj.id} distance=#{proj.horizon_distance.round(2)} construal=#{proj.construal_level}"
64
- Legion::Logging.debug msg
64
+ log.debug msg
65
65
  proj.to_h
66
66
  end
67
67
 
68
68
  def projections_within_horizon(**)
69
69
  within = horizon_engine.projections_within_horizon
70
- Legion::Logging.debug "[cognitive_horizon] within_horizon: count=#{within.size} effective=#{horizon_engine.effective_horizon.round(2)}"
70
+ log.debug "[cognitive_horizon] within_horizon: count=#{within.size} effective=#{horizon_engine.effective_horizon.round(2)}"
71
71
  { count: within.size, projections: within.map(&:to_h), effective_horizon: horizon_engine.effective_horizon.round(10) }
72
72
  end
73
73
 
74
74
  def beyond_horizon_projections(**)
75
75
  beyond = horizon_engine.beyond_horizon_projections
76
- Legion::Logging.debug "[cognitive_horizon] beyond_horizon: count=#{beyond.size}"
76
+ log.debug "[cognitive_horizon] beyond_horizon: count=#{beyond.size}"
77
77
  { count: beyond.size, projections: beyond.map(&:to_h), effective_horizon: horizon_engine.effective_horizon.round(10) }
78
78
  end
79
79
 
80
80
  def nearest_projections(count: 5, **)
81
81
  projs = horizon_engine.nearest_projections(num: count)
82
- Legion::Logging.debug "[cognitive_horizon] nearest_projections: count=#{count} returned=#{projs.size}"
82
+ log.debug "[cognitive_horizon] nearest_projections: count=#{count} returned=#{projs.size}"
83
83
  { count: projs.size, projections: projs.map(&:to_h) }
84
84
  end
85
85
 
86
86
  def farthest_projections(count: 5, **)
87
87
  projs = horizon_engine.farthest_projections(num: count)
88
- Legion::Logging.debug "[cognitive_horizon] farthest_projections: count=#{count} returned=#{projs.size}"
88
+ log.debug "[cognitive_horizon] farthest_projections: count=#{count} returned=#{projs.size}"
89
89
  { count: projs.size, projections: projs.map(&:to_h) }
90
90
  end
91
91
 
@@ -14,7 +14,7 @@ module Legion
14
14
 
15
15
  def propose_hypothesis(description:, domain: 'general', prior: Helpers::Constants::PRIOR_DEFAULT, **)
16
16
  h = hypothesis_engine.propose(description: description, domain: domain, prior: prior)
17
- Legion::Logging.debug "[hypothesis_testing] proposed id=#{h.id[0..7]} domain=#{domain} prior=#{prior}"
17
+ log.debug "[hypothesis_testing] proposed id=#{h.id[0..7]} domain=#{domain} prior=#{prior}"
18
18
  {
19
19
  hypothesis_id: h.id,
20
20
  description: h.description,
@@ -33,13 +33,13 @@ module Legion
33
33
  supporting: supporting
34
34
  )
35
35
  unless h
36
- Legion::Logging.debug "[hypothesis_testing] test failed: #{hypothesis_id[0..7]} not found"
36
+ log.debug "[hypothesis_testing] test failed: #{hypothesis_id[0..7]} not found"
37
37
  return { tested: false, reason: :not_found }
38
38
  end
39
39
 
40
- Legion::Logging.info "[hypothesis_testing] tested #{hypothesis_id[0..7]} " \
41
- "supporting=#{supporting} strength=#{evidence_strength} " \
42
- "posterior=#{h.posterior.round(4)} status=#{h.status}"
40
+ log.info "[hypothesis_testing] tested #{hypothesis_id[0..7]} " \
41
+ "supporting=#{supporting} strength=#{evidence_strength} " \
42
+ "posterior=#{h.posterior.round(4)} status=#{h.status}"
43
43
  {
44
44
  tested: true,
45
45
  hypothesis_id: h.id,
@@ -53,11 +53,11 @@ module Legion
53
53
  def evaluate_hypothesis(hypothesis_id:, **)
54
54
  h = hypothesis_engine.evaluate(hypothesis_id)
55
55
  unless h
56
- Legion::Logging.debug "[hypothesis_testing] evaluate failed: #{hypothesis_id[0..7]} not found"
56
+ log.debug "[hypothesis_testing] evaluate failed: #{hypothesis_id[0..7]} not found"
57
57
  return { found: false }
58
58
  end
59
59
 
60
- Legion::Logging.debug "[hypothesis_testing] evaluated #{hypothesis_id[0..7]} status=#{h.status}"
60
+ log.debug "[hypothesis_testing] evaluated #{hypothesis_id[0..7]} status=#{h.status}"
61
61
  {
62
62
  found: true,
63
63
  hypothesis_id: h.id,
@@ -70,7 +70,7 @@ module Legion
70
70
 
71
71
  def competing_hypotheses(domain:, **)
72
72
  hypotheses = hypothesis_engine.competing_hypotheses(domain: domain)
73
- Legion::Logging.debug "[hypothesis_testing] competing count=#{hypotheses.size} domain=#{domain}"
73
+ log.debug "[hypothesis_testing] competing count=#{hypotheses.size} domain=#{domain}"
74
74
  {
75
75
  domain: domain,
76
76
  count: hypotheses.size,
@@ -80,7 +80,7 @@ module Legion
80
80
 
81
81
  def most_confident_hypotheses(limit: 5, **)
82
82
  hypotheses = hypothesis_engine.most_confident(limit: limit)
83
- Legion::Logging.debug "[hypothesis_testing] most_confident count=#{hypotheses.size}"
83
+ log.debug "[hypothesis_testing] most_confident count=#{hypotheses.size}"
84
84
  {
85
85
  count: hypotheses.size,
86
86
  hypotheses: hypotheses.map(&:to_h)
@@ -89,8 +89,8 @@ module Legion
89
89
 
90
90
  def hypothesis_report(**)
91
91
  report = hypothesis_engine.hypothesis_report
92
- Legion::Logging.debug "[hypothesis_testing] report total=#{report[:total]} " \
93
- "confirmation_rate=#{report[:confirmation_rate].round(4)}"
92
+ log.debug "[hypothesis_testing] report total=#{report[:total]} " \
93
+ "confirmation_rate=#{report[:confirmation_rate].round(4)}"
94
94
  report
95
95
  end
96
96
 
@@ -7,6 +7,8 @@ module Legion
7
7
  module Magnet
8
8
  module Helpers
9
9
  class MagnetEngine
10
+ include Legion::Logging::Helper
11
+
10
12
  attr_reader :poles, :fields, :interaction_log
11
13
 
12
14
  def initialize
@@ -34,12 +34,12 @@ module Legion
34
34
  )
35
35
 
36
36
  if result.is_a?(Hash) && result[:error]
37
- Legion::Logging.warn "[cognitive_magnet] create_pole failed: #{result[:error]}"
37
+ log.warn "[cognitive_magnet] create_pole failed: #{result[:error]}"
38
38
  return { success: false, **result }
39
39
  end
40
40
 
41
- Legion::Logging.debug "[cognitive_magnet] pole created id=#{result.id[0..7]} " \
42
- "polarity=#{polarity} strength=#{strength}"
41
+ log.debug "[cognitive_magnet] pole created id=#{result.id[0..7]} " \
42
+ "polarity=#{polarity} strength=#{strength}"
43
43
  { success: true, pole: result.to_h }
44
44
  rescue ArgumentError => e
45
45
  { success: false, error: :argument_error, message: e.message }
@@ -50,11 +50,11 @@ module Legion
50
50
  result = eng.create_field(name: name)
51
51
 
52
52
  if result.is_a?(Hash) && result[:error]
53
- Legion::Logging.warn "[cognitive_magnet] create_field failed: #{result[:error]}"
53
+ log.warn "[cognitive_magnet] create_field failed: #{result[:error]}"
54
54
  return { success: false, **result }
55
55
  end
56
56
 
57
- Legion::Logging.debug "[cognitive_magnet] field created id=#{result.id[0..7]} name=#{name}"
57
+ log.debug "[cognitive_magnet] field created id=#{result.id[0..7]} name=#{name}"
58
58
  { success: true, field: result.to_h }
59
59
  rescue ArgumentError => e
60
60
  { success: false, error: :argument_error, message: e.message }
@@ -65,11 +65,11 @@ module Legion
65
65
  result = eng.magnetize(pole_id, rate: rate)
66
66
 
67
67
  if result[:error]
68
- Legion::Logging.warn "[cognitive_magnet] magnetize failed: #{result[:error]}"
68
+ log.warn "[cognitive_magnet] magnetize failed: #{result[:error]}"
69
69
  return { success: false, **result }
70
70
  end
71
71
 
72
- Legion::Logging.debug "[cognitive_magnet] magnetized id=#{pole_id[0..7]} strength=#{result[:strength]}"
72
+ log.debug "[cognitive_magnet] magnetized id=#{pole_id[0..7]} strength=#{result[:strength]}"
73
73
  { success: true, **result }
74
74
  rescue ArgumentError => e
75
75
  { success: false, error: :argument_error, message: e.message }
@@ -80,12 +80,12 @@ module Legion
80
80
  result = eng.interact(pole_a_id, pole_b_id)
81
81
 
82
82
  if result[:error]
83
- Legion::Logging.warn "[cognitive_magnet] interact failed: #{result[:error]}"
83
+ log.warn "[cognitive_magnet] interact failed: #{result[:error]}"
84
84
  return { success: false, **result }
85
85
  end
86
86
 
87
- Legion::Logging.debug "[cognitive_magnet] interaction type=#{result[:type]} " \
88
- "force=#{result[:force].round(4)}"
87
+ log.debug "[cognitive_magnet] interaction type=#{result[:type]} " \
88
+ "force=#{result[:force].round(4)}"
89
89
  { success: true, **result }
90
90
  rescue ArgumentError => e
91
91
  { success: false, error: :argument_error, message: e.message }
@@ -94,7 +94,7 @@ module Legion
94
94
  def list_poles(engine: nil, limit: 50, **)
95
95
  eng = engine || magnet_engine
96
96
  poles = eng.poles.values.first(limit).map(&:to_h)
97
- Legion::Logging.debug "[cognitive_magnet] list_poles count=#{poles.size}"
97
+ log.debug "[cognitive_magnet] list_poles count=#{poles.size}"
98
98
  { success: true, poles: poles, count: poles.size }
99
99
  rescue ArgumentError => e
100
100
  { success: false, error: :argument_error, message: e.message }
@@ -103,8 +103,8 @@ module Legion
103
103
  def magnetic_status(engine: nil, **)
104
104
  eng = engine || magnet_engine
105
105
  report = eng.field_report
106
- Legion::Logging.debug "[cognitive_magnet] status: poles=#{report[:total_poles]} " \
107
- "fields=#{report[:total_fields]} interactions=#{report[:total_interactions]}"
106
+ log.debug "[cognitive_magnet] status: poles=#{report[:total_poles]} " \
107
+ "fields=#{report[:total_fields]} interactions=#{report[:total_interactions]}"
108
108
  { success: true, report: report }
109
109
  rescue ArgumentError => e
110
110
  { success: false, error: :argument_error, message: e.message }
@@ -17,73 +17,73 @@ module Legion
17
17
  domain: domain.to_sym,
18
18
  mass: mass || Helpers::Constants::DEFAULT_MASS
19
19
  )
20
- Legion::Logging.debug "[cognitive_momentum] create id=#{idea.id[0..7]} " \
21
- "type=#{idea_type} domain=#{domain}"
20
+ log.debug "[cognitive_momentum] create id=#{idea.id[0..7]} " \
21
+ "type=#{idea_type} domain=#{domain}"
22
22
  { success: true, idea: idea.to_h }
23
23
  end
24
24
 
25
25
  def reinforce_cognitive_idea(idea_id:, **)
26
26
  result = engine.reinforce_idea(idea_id: idea_id)
27
- Legion::Logging.debug "[cognitive_momentum] reinforce id=#{idea_id[0..7]} " \
28
- "momentum=#{result[:momentum]&.round(3)}"
27
+ log.debug "[cognitive_momentum] reinforce id=#{idea_id[0..7]} " \
28
+ "momentum=#{result[:momentum]&.round(3)}"
29
29
  result
30
30
  end
31
31
 
32
32
  def challenge_cognitive_idea(idea_id:, **)
33
33
  result = engine.challenge_idea(idea_id: idea_id)
34
- Legion::Logging.debug "[cognitive_momentum] challenge id=#{idea_id[0..7]} " \
35
- "momentum=#{result[:momentum]&.round(3)}"
34
+ log.debug "[cognitive_momentum] challenge id=#{idea_id[0..7]} " \
35
+ "momentum=#{result[:momentum]&.round(3)}"
36
36
  result
37
37
  end
38
38
 
39
39
  def apply_cognitive_force(idea_id:, force:, **)
40
40
  result = engine.apply_force(idea_id: idea_id, force: force)
41
- Legion::Logging.debug "[cognitive_momentum] force id=#{idea_id[0..7]} " \
42
- "f=#{force} momentum=#{result[:momentum]&.round(3)}"
41
+ log.debug "[cognitive_momentum] force id=#{idea_id[0..7]} " \
42
+ "f=#{force} momentum=#{result[:momentum]&.round(3)}"
43
43
  result
44
44
  end
45
45
 
46
46
  def surging_ideas_report(**)
47
47
  ideas = engine.surging_ideas
48
- Legion::Logging.debug "[cognitive_momentum] surging count=#{ideas.size}"
48
+ log.debug "[cognitive_momentum] surging count=#{ideas.size}"
49
49
  { success: true, ideas: ideas.map(&:to_h), count: ideas.size }
50
50
  end
51
51
 
52
52
  def reversing_ideas_report(**)
53
53
  ideas = engine.reversing_ideas
54
- Legion::Logging.debug "[cognitive_momentum] reversing count=#{ideas.size}"
54
+ log.debug "[cognitive_momentum] reversing count=#{ideas.size}"
55
55
  { success: true, ideas: ideas.map(&:to_h), count: ideas.size }
56
56
  end
57
57
 
58
58
  def entrenched_ideas_report(**)
59
59
  ideas = engine.entrenched_ideas
60
- Legion::Logging.debug "[cognitive_momentum] entrenched count=#{ideas.size}"
60
+ log.debug "[cognitive_momentum] entrenched count=#{ideas.size}"
61
61
  { success: true, ideas: ideas.map(&:to_h), count: ideas.size }
62
62
  end
63
63
 
64
64
  def highest_momentum_ideas(limit: 5, **)
65
65
  ideas = engine.highest_momentum(limit: limit)
66
- Legion::Logging.debug "[cognitive_momentum] highest_momentum count=#{ideas.size}"
66
+ log.debug "[cognitive_momentum] highest_momentum count=#{ideas.size}"
67
67
  { success: true, ideas: ideas.map(&:to_h), count: ideas.size }
68
68
  end
69
69
 
70
70
  def ideas_by_domain(domain:, **)
71
71
  ideas = engine.ideas_by_domain(domain: domain.to_sym)
72
- Legion::Logging.debug '[cognitive_momentum] by_domain ' \
73
- "domain=#{domain} count=#{ideas.size}"
72
+ log.debug '[cognitive_momentum] by_domain ' \
73
+ "domain=#{domain} count=#{ideas.size}"
74
74
  { success: true, ideas: ideas.map(&:to_h), count: ideas.size }
75
75
  end
76
76
 
77
77
  def update_cognitive_momentum(**)
78
78
  engine.apply_friction_all
79
79
  pruned = engine.prune_at_rest
80
- Legion::Logging.debug "[cognitive_momentum] friction+prune pruned=#{pruned}"
80
+ log.debug "[cognitive_momentum] friction+prune pruned=#{pruned}"
81
81
  { success: true, pruned: pruned }
82
82
  end
83
83
 
84
84
  def cognitive_momentum_stats(**)
85
85
  stats = engine.to_h
86
- Legion::Logging.debug "[cognitive_momentum] stats total=#{stats[:total_ideas]}"
86
+ log.debug "[cognitive_momentum] stats total=#{stats[:total_ideas]}"
87
87
  { success: true }.merge(stats)
88
88
  end
89
89
 
@@ -7,6 +7,8 @@ module Legion
7
7
  module PerceptualInference
8
8
  module Helpers
9
9
  class PerceptualField
10
+ include Legion::Logging::Helper
11
+
10
12
  attr_reader :hypotheses, :evidence_log
11
13
 
12
14
  def initialize
@@ -11,31 +11,31 @@ module Legion
11
11
 
12
12
  def register_percept_hypothesis(content:, modality:, domain: :general, prior: Helpers::DEFAULT_PRIOR, **)
13
13
  hypothesis = field.register_hypothesis(content: content, modality: modality, domain: domain, prior: prior)
14
- Legion::Logging.debug "[perceptual_inference] registered hypothesis modality=#{modality} id=#{hypothesis.id[0..7]}"
14
+ log.debug "[perceptual_inference] registered hypothesis modality=#{modality} id=#{hypothesis.id[0..7]}"
15
15
  { success: true, hypothesis_id: hypothesis.id, modality: modality, prior: hypothesis.prior }
16
16
  rescue ArgumentError => e
17
- Legion::Logging.warn "[perceptual_inference] register failed: #{e.message}"
17
+ log.warn "[perceptual_inference] register failed: #{e.message}"
18
18
  { success: false, error: e.message }
19
19
  end
20
20
 
21
21
  def present_perceptual_evidence(modality:, content:, strength: 0.5, **)
22
22
  count = field.present_evidence(modality: modality, content: content, strength: strength)
23
- Legion::Logging.debug "[perceptual_inference] evidence presented modality=#{modality} strength=#{strength} updated=#{count}"
23
+ log.debug "[perceptual_inference] evidence presented modality=#{modality} strength=#{strength} updated=#{count}"
24
24
  { success: true, modality: modality, hypotheses_updated: count, rivalry: field.rivalry?(modality: modality) }
25
25
  rescue ArgumentError => e
26
- Legion::Logging.warn "[perceptual_inference] evidence failed: #{e.message}"
26
+ log.warn "[perceptual_inference] evidence failed: #{e.message}"
27
27
  { success: false, error: e.message }
28
28
  end
29
29
 
30
30
  def select_percept(modality:, **)
31
31
  winner = field.select_percept(modality: modality)
32
32
  if winner
33
- Legion::Logging.info "[perceptual_inference] percept selected modality=#{modality} " \
34
- "posterior=#{winner.posterior.round(3)} label=#{winner.percept_label}"
33
+ log.info "[perceptual_inference] percept selected modality=#{modality} " \
34
+ "posterior=#{winner.posterior.round(3)} label=#{winner.percept_label}"
35
35
  { success: true, selected: true, hypothesis: winner.to_h }
36
36
  else
37
37
  rivalry = field.rivalry?(modality: modality)
38
- Legion::Logging.debug "[perceptual_inference] no percept selected modality=#{modality} rivalry=#{rivalry}"
38
+ log.debug "[perceptual_inference] no percept selected modality=#{modality} rivalry=#{rivalry}"
39
39
  { success: true, selected: false, rivalry: rivalry }
40
40
  end
41
41
  rescue ArgumentError => e
@@ -46,7 +46,7 @@ module Legion
46
46
  rival = field.rivalry?(modality: modality)
47
47
  candidates = field.hypotheses_for(modality)
48
48
  top_two = candidates.select { |h| %i[active selected].include?(h.state) }.max_by(2, &:posterior)
49
- Legion::Logging.debug "[perceptual_inference] rivalry check modality=#{modality} rival=#{rival}"
49
+ log.debug "[perceptual_inference] rivalry check modality=#{modality} rival=#{rival}"
50
50
  { success: true, rivalry: rival, modality: modality, top_hypotheses: top_two.map(&:to_h) }
51
51
  rescue ArgumentError => e
52
52
  { success: false, error: e.message }
@@ -65,7 +65,7 @@ module Legion
65
65
 
66
66
  def adapt_perception(modality:, correct_hypothesis_id:, **)
67
67
  field.adapt_priors(modality: modality, correct_hypothesis_id: correct_hypothesis_id)
68
- Legion::Logging.info "[perceptual_inference] priors adapted modality=#{modality} correct=#{correct_hypothesis_id[0..7]}"
68
+ log.info "[perceptual_inference] priors adapted modality=#{modality} correct=#{correct_hypothesis_id[0..7]}"
69
69
  { success: true, modality: modality, correct_hypothesis_id: correct_hypothesis_id }
70
70
  rescue ArgumentError => e
71
71
  { success: false, error: e.message }
@@ -73,20 +73,20 @@ module Legion
73
73
 
74
74
  def suppress_percept(hypothesis_id:, **)
75
75
  suppressed = field.suppress_hypothesis(hypothesis_id: hypothesis_id)
76
- Legion::Logging.debug "[perceptual_inference] suppress hypothesis_id=#{hypothesis_id[0..7]} result=#{suppressed}"
76
+ log.debug "[perceptual_inference] suppress hypothesis_id=#{hypothesis_id[0..7]} result=#{suppressed}"
77
77
  { success: true, suppressed: suppressed, hypothesis_id: hypothesis_id }
78
78
  end
79
79
 
80
80
  def perceptual_ambiguity(**)
81
81
  level = field.ambiguity_level
82
82
  label = ambiguity_label(level)
83
- Legion::Logging.debug "[perceptual_inference] ambiguity=#{level.round(3)} label=#{label}"
83
+ log.debug "[perceptual_inference] ambiguity=#{level.round(3)} label=#{label}"
84
84
  { success: true, ambiguity_level: level, label: label }
85
85
  end
86
86
 
87
87
  def update_perceptual_inference(**)
88
88
  field.decay_all
89
- Legion::Logging.debug "[perceptual_inference] decay cycle complete remaining=#{field.hypotheses.size}"
89
+ log.debug "[perceptual_inference] decay cycle complete remaining=#{field.hypotheses.size}"
90
90
  { success: true, remaining_hypotheses: field.hypotheses.size }
91
91
  end
92
92
 
@@ -29,8 +29,8 @@ module Legion
29
29
  prediction_store.store(prediction)
30
30
 
31
31
  actionable = prediction[:confidence] >= Helpers::Modes::PREDICTION_CONFIDENCE_MIN
32
- Legion::Logging.debug "[prediction] new: mode=#{mode} confidence=#{prediction[:confidence].round(2)} " \
33
- "actionable=#{actionable} id=#{prediction[:prediction_id][0..7]}"
32
+ log.debug "[prediction] new: mode=#{mode} confidence=#{prediction[:confidence].round(2)} " \
33
+ "actionable=#{actionable} id=#{prediction[:prediction_id][0..7]}"
34
34
 
35
35
  {
36
36
  prediction_id: prediction[:prediction_id],
@@ -43,25 +43,25 @@ module Legion
43
43
  def resolve_prediction(prediction_id:, outcome:, actual: nil, **)
44
44
  pred = prediction_store.resolve(prediction_id, outcome: outcome, actual: actual)
45
45
  if pred
46
- Legion::Logging.info "[prediction] resolved #{prediction_id[0..7]} outcome=#{outcome}"
46
+ log.info "[prediction] resolved #{prediction_id[0..7]} outcome=#{outcome}"
47
47
  record_outcome_trace(pred, outcome)
48
48
  { resolved: true, prediction_id: prediction_id, outcome: outcome }
49
49
  else
50
- Legion::Logging.debug "[prediction] resolve failed: #{prediction_id[0..7]} not found"
50
+ log.debug "[prediction] resolve failed: #{prediction_id[0..7]} not found"
51
51
  { resolved: false, reason: :not_found }
52
52
  end
53
53
  end
54
54
 
55
55
  def pending_predictions(**)
56
56
  preds = prediction_store.pending
57
- Legion::Logging.debug "[prediction] pending count=#{preds.size}"
57
+ log.debug "[prediction] pending count=#{preds.size}"
58
58
  { predictions: preds, count: preds.size }
59
59
  end
60
60
 
61
61
  def prediction_accuracy(window: 100, **)
62
62
  acc = prediction_store.accuracy(window: window)
63
63
  total = prediction_store.outcomes.size
64
- Legion::Logging.debug "[prediction] accuracy=#{acc.round(2)} total_outcomes=#{total}"
64
+ log.debug "[prediction] accuracy=#{acc.round(2)} total_outcomes=#{total}"
65
65
  { accuracy: acc, total_outcomes: total }
66
66
  end
67
67
 
@@ -77,7 +77,7 @@ module Legion
77
77
  end
78
78
 
79
79
  remaining = prediction_store.pending.size
80
- Legion::Logging.debug "[prediction] expire sweep: expired=#{expired_count} remaining=#{remaining}"
80
+ log.debug "[prediction] expire sweep: expired=#{expired_count} remaining=#{remaining}"
81
81
 
82
82
  { expired_count: expired_count, remaining_pending: remaining }
83
83
  end
@@ -133,9 +133,9 @@ module Legion
133
133
  store = runner.send(:default_store)
134
134
  store.flush if store.respond_to?(:flush)
135
135
 
136
- Legion::Logging.debug "[prediction] created #{trace_params[:type]} trace for #{outcome} prediction"
136
+ log.debug "[prediction] created #{trace_params[:type]} trace for #{outcome} prediction"
137
137
  rescue StandardError => e
138
- Legion::Logging.warn "[prediction] failed to create outcome trace: #{e.message}"
138
+ log.warn "[prediction] failed to create outcome trace: #{e.message}"
139
139
  end
140
140
  end
141
141
  end