Class: Legion::Extensions::Agentic::Self::Metacognition::Helpers::RegistryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistryStore

Returns a new instance of RegistryStore.



10
11
12
13
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 10

def initialize
  @extensions = {}
  @mutex = Mutex.new
end

Instance Method Details

#by_health(threshold: 0.4) ⇒ Object



59
60
61
62
63
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 59

def by_health(threshold: 0.4)
  @mutex.synchronize do
    @extensions.values.select { |e| e[:health_score] && e[:health_score] < threshold }.map(&:dup)
  end
end

#category_distributionObject



49
50
51
52
53
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 49

def category_distribution
  @mutex.synchronize do
    @extensions.values.group_by { |e| e[:category] }.transform_values(&:count)
  end
end

#countObject



55
56
57
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 55

def count
  @mutex.synchronize { @extensions.size }
end

#deregister(name) ⇒ Object



23
24
25
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 23

def deregister(name)
  @mutex.synchronize { @extensions.delete(name) }
end

#get(name) ⇒ Object



27
28
29
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 27

def get(name)
  @mutex.synchronize { @extensions[name]&.dup }
end

#list(status: nil, category: nil) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 31

def list(status: nil, category: nil)
  @mutex.synchronize do
    result = @extensions.values
    result = result.select { |e| e[:status] == status.to_s } if status
    result = result.select { |e| e[:category] == category.to_s } if category
    result.map(&:dup)
  end
end

#register(entry) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 15

def register(entry)
  @mutex.synchronize do
    now = Time.now.utc
    defaults = { invocation_count: 0, health_score: 1.0 }
    @extensions[entry[:name]] = defaults.merge(entry).merge(created_at: now, updated_at: now)
  end
end

#update(name, attrs) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb', line 40

def update(name, attrs)
  @mutex.synchronize do
    return nil unless @extensions[name]

    @extensions[name] = @extensions[name].merge(attrs).merge(updated_at: Time.now.utc)
    @extensions[name].dup
  end
end