Module: Legion::Extensions::Agentic::Self::Metacognition::Runners::Metacognition

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

Instance Method Summary collapse

Instance Method Details

#architecture_changesObject



81
82
83
84
85
86
# File 'lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb', line 81

def architecture_changes(**)
  {
    changes:   snapshot_store.architecture_changes,
    snapshots: snapshot_store.size
  }
end

#architecture_overviewObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb', line 61

def architecture_overview(**)
  model = snapshot_store.latest || Helpers::SelfModel.build
  snapshot_store.store(model) if snapshot_store.stale?

  {
    identity:     model[:identity],
    architecture: model[:architecture],
    capabilities: model[:capabilities],
    assembled_at: model[:assembled_at]
  }
end

#explain_subsystem(subsystem:) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb', line 42

def explain_subsystem(subsystem:, **)
  sym = subsystem.to_sym
  ext_sym = sym.to_s.split('_').map(&:capitalize).join.to_sym

  loaded = Helpers::SelfModel.extension_loaded?(ext_sym)
  category = Helpers::Constants::EXTENSION_CAPABILITIES[ext_sym] || :unknown

  latest = snapshot_store.latest
  state = latest&.dig(:subsystems, sym)

  {
    subsystem: sym,
    extension: ext_sym,
    loaded:    loaded,
    category:  category,
    state:     state || { status: :no_data }
  }
end

#health_trend(limit: 20) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb', line 73

def health_trend(limit: 20, **)
  {
    trend:     snapshot_store.health_trend(limit: limit),
    snapshots: snapshot_store.size,
    current:   snapshot_store.latest&.dig(:cognitive, :health)
  }
end

#introspect(tick_results: {}, subsystem_states: {}) ⇒ Object



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

def introspect(tick_results: {}, subsystem_states: {}, **)
  model = if snapshot_store.stale?
            fresh = Helpers::SelfModel.build(
              subsystem_states: subsystem_states,
              tick_results:     tick_results
            )
            snapshot_store.store(fresh)
            fresh
          else
            snapshot_store.latest
          end

  log.debug "[metacognition] introspect: #{model.dig(:architecture, :loaded_count)} extensions loaded"
  model
end

#metacognition_statsObject



88
89
90
91
92
93
94
95
96
# File 'lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb', line 88

def metacognition_stats(**)
  {
    snapshots_stored:   snapshot_store.size,
    latest_stale:       snapshot_store.stale?,
    loaded_extensions:  snapshot_store.latest&.dig(:architecture, :loaded_count) || 0,
    cognitive_health:   snapshot_store.latest&.dig(:cognitive, :health),
    capability_summary: capability_summary
  }
end

#self_narrative(tick_results: {}, subsystem_states: {}) ⇒ Object



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

def self_narrative(tick_results: {}, subsystem_states: {}, **)
  model = introspect(tick_results: tick_results, subsystem_states: subsystem_states)
  prose = Helpers::NarratorBridge.narrate_self_model(model)

  {
    prose:     prose,
    health:    model.dig(:cognitive, :health),
    mode:      model.dig(:cognitive, :mode),
    model:     model,
    timestamp: Time.now.utc
  }
end