Class: KairosMcp::LayerRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/kairos_mcp/layer_registry.rb

Overview

LayerRegistry: Manages the layered architecture for skills and knowledge

Layer hierarchy (legal system analogy):

L0-A (Constitution): skills/kairos.md - Immutable philosophy
L0-B (Law): skills/kairos.rb - Self-modifying meta-rules with full blockchain record
L1 (Ordinance): knowledge/ - Project knowledge with hash-only blockchain record
L2 (Context): context/ - Temporary context without blockchain record

Constant Summary collapse

LAYERS =
{
  L0_constitution: {
    path: 'skills/kairos.md',
    mutable: false,
    blockchain: :none,
    format: :markdown,
    description: 'Kairos philosophy and principles (read-only)'
  },
  L0_law: {
    path: 'skills/kairos.rb',
    mutable: true,
    blockchain: :full,
    format: :ruby_dsl,
    description: 'Kairos meta-rules (self-modifying constraints)'
  },
  L1: {
    path: 'knowledge/',
    mutable: true,
    blockchain: :hash_only,
    format: :anthropic_skill,
    description: 'Project knowledge (Anthropic skills format)'
  },
  L2: {
    path: 'context/',
    mutable: true,
    blockchain: :none,
    format: :anthropic_skill,
    description: 'Temporary context (free modification)'
  }
}.freeze
KAIROS_META_SKILLS_FALLBACK =

Kairos meta-skills that can be placed in L0 NOTE: This is a fallback. The canonical source is the l0_governance skill. See: kairos.md SPEC-010 (Pure Agent Skill Specification)

%i[
  core_safety
  l0_governance
  evolution_rules
  layer_awareness
  approval_workflow
  self_inspection
  chain_awareness
  audit_rules
].freeze
SKILLSET_LAYER_MAP =

Map SkillSet layer symbols to internal layer keys

{
  L0: :L0_law,
  L1: :L1,
  L2: :L2
}.freeze

Class Method Summary collapse

Class Method Details

.all_layersObject

Get all layer names



128
129
130
# File 'lib/kairos_mcp/layer_registry.rb', line 128

def all_layers
  LAYERS.keys
end

.blockchain_mode(layer) ⇒ Object

Get blockchain recording mode for a layer Supports both internal layer keys (L0_constitution, L0_law) and SkillSet layer symbols (:L0, :L1, :L2)



82
83
84
85
# File 'lib/kairos_mcp/layer_registry.rb', line 82

def blockchain_mode(layer)
  layer = normalize_layer(layer)
  LAYERS[layer]&.[](:blockchain) || :none
end

.can_modify?(layer) ⇒ Boolean

Check if a layer allows modification

Returns:

  • (Boolean)


68
69
70
# File 'lib/kairos_mcp/layer_registry.rb', line 68

def can_modify?(layer)
  LAYERS[layer]&.[](:mutable) || false
end

.description_for(layer) ⇒ Object

Get layer description



98
99
100
# File 'lib/kairos_mcp/layer_registry.rb', line 98

def description_for(layer)
  LAYERS[layer]&.[](:description)
end

.format_for(layer) ⇒ Object

Get the format type for a layer



88
89
90
# File 'lib/kairos_mcp/layer_registry.rb', line 88

def format_for(layer)
  LAYERS[layer]&.[](:format)
end

.kairos_meta_skill?(skill_id) ⇒ Boolean

Check if a skill ID is a Kairos meta-skill (allowed in L0)

Returns:

  • (Boolean)


123
124
125
# File 'lib/kairos_mcp/layer_registry.rb', line 123

def kairos_meta_skill?(skill_id)
  kairos_meta_skills.include?(skill_id.to_sym)
end

.kairos_meta_skillsObject

Get allowed L0 skills from l0_governance skill (or fallback) Implements Pure Agent Skill principle: L0 rules are in L0



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/kairos_mcp/layer_registry.rb', line 104

def kairos_meta_skills
  # Try to get from l0_governance skill first (canonical source)
  if defined?(Kairos) && Kairos.respond_to?(:skill)
    governance_skill = Kairos.skill(:l0_governance)
    if governance_skill&.behavior
      begin
        config = governance_skill.behavior.call
        return config[:allowed_skills] if config[:allowed_skills]
      rescue StandardError
        # Fall through to fallback
      end
    end
  end
  
  # Fallback for bootstrapping
  KAIROS_META_SKILLS_FALLBACK
end

.layer_for(path) ⇒ Object

Get layer configuration for a given path



62
63
64
65
# File 'lib/kairos_mcp/layer_registry.rb', line 62

def layer_for(path)
  relative_path = normalize_path(path)
  LAYERS.find { |_, config| relative_path.start_with?(config[:path]) }&.first
end

.path_for(layer) ⇒ Object

Get the base path for a layer



93
94
95
# File 'lib/kairos_mcp/layer_registry.rb', line 93

def path_for(layer)
  LAYERS[layer]&.[](:path)
end

.requires_blockchain?(layer) ⇒ Boolean

Check if a layer requires blockchain recording Supports both internal layer keys and SkillSet layer symbols

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/kairos_mcp/layer_registry.rb', line 74

def requires_blockchain?(layer)
  mode = blockchain_mode(layer)
  mode && mode != :none
end

.summaryObject

Get layer summary



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/kairos_mcp/layer_registry.rb', line 133

def summary
  LAYERS.map do |layer, config|
    {
      layer: layer,
      path: config[:path],
      mutable: config[:mutable],
      blockchain: config[:blockchain],
      format: config[:format],
      description: config[:description]
    }
  end
end

.validate_skill_layer(skill_id, target_layer) ⇒ Object

Validate that a skill belongs to the correct layer



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/kairos_mcp/layer_registry.rb', line 147

def validate_skill_layer(skill_id, target_layer)
  case target_layer
  when :L0_law
    unless kairos_meta_skill?(skill_id)
      allowed = kairos_meta_skills.join(', ')
      return {
        valid: false,
        error: "Skill '#{skill_id}' is not allowed in L0. " \
               "Allowed skills (from l0_governance): #{allowed}. " \
               "To add a new skill type, first evolve the l0_governance skill."
      }
    end
  when :L0_constitution
    return { valid: false, error: 'L0 constitution (kairos.md) is immutable.' }
  end

  { valid: true }
end