Module: Legion::Extensions::Agentic::Self::Identity::Runners::Identity

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/self/identity/runners/identity.rb

Instance Method Summary collapse

Instance Method Details

#check_entropy(observations: {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/self/identity/runners/identity.rb', line 40

def check_entropy(observations: {}, **)
  fingerprint = identity_fingerprint
  entropy = fingerprint.current_entropy(observations)
  classification = Helpers::Dimensions.classify_entropy(entropy)
  trend = fingerprint.entropy_trend

  result = {
    entropy:        entropy,
    classification: classification,
    trend:          trend,
    in_range:       Helpers::Dimensions::OPTIMAL_ENTROPY_RANGE.cover?(entropy)
  }

  case classification
  when :high_entropy
    result[:warning] = :possible_impersonation_or_drift
    result[:action] = :enter_caution_mode
    log.warn "[identity] high entropy detected: #{entropy.round(3)} trend=#{trend} - possible impersonation"
  when :low_entropy
    result[:warning] = :possible_automation
    result[:action] = :trigger_verification
    log.warn "[identity] low entropy detected: #{entropy.round(3)} trend=#{trend} - possible automation"
  else
    log.debug "[identity] entropy check: #{entropy.round(3)} classification=#{classification} trend=#{trend}"
  end

  result
end

#identity_maturityObject



75
76
77
# File 'lib/legion/extensions/agentic/self/identity/runners/identity.rb', line 75

def identity_maturity(**)
  { maturity: identity_fingerprint.maturity }
end

#identity_statusObject



69
70
71
72
73
# File 'lib/legion/extensions/agentic/self/identity/runners/identity.rb', line 69

def identity_status(**)
  fingerprint = identity_fingerprint
  log.debug "[identity] status: maturity=#{fingerprint.maturity} observations=#{fingerprint.observation_count}"
  fingerprint.to_h
end

#observe_all(observations:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/self/identity/runners/identity.rb', line 27

def observe_all(observations:, **)
  fingerprint = identity_fingerprint
  fingerprint.observe_all(observations)

  log.debug "[identity] observe_all: dims=#{observations.keys.join(',')} " \
            "obs=#{fingerprint.observation_count} maturity=#{fingerprint.maturity}"
  {
    dimensions_observed: observations.keys,
    observation_count:   fingerprint.observation_count,
    maturity:            fingerprint.maturity
  }
end

#observe_behavior(dimension:, value:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/self/identity/runners/identity.rb', line 13

def observe_behavior(dimension:, value:, **)
  fingerprint = identity_fingerprint
  fingerprint.observe(dimension, value)

  log.debug "[identity] observe: dim=#{dimension} val=#{value.round(2)} " \
            "obs=#{fingerprint.observation_count} maturity=#{fingerprint.maturity}"
  {
    dimension:         dimension,
    recorded:          true,
    observation_count: fingerprint.observation_count,
    maturity:          fingerprint.maturity
  }
end