Class: SwarmMemory::SkillState
- Inherits:
-
Object
- Object
- SwarmMemory::SkillState
- Defined in:
- lib/swarm_memory/skill_state.rb
Overview
Immutable representation of a loaded skill's state
This object encapsulates all skill-related state for clean management. Immutability prevents accidental mutation bugs during activation.
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#allows_tool?(name) ⇒ Boolean
Check if a specific tool is allowed by this skill.
-
#initialize(file_path:, tools: nil, permissions: {}) ⇒ SkillState
constructor
Create a new SkillState.
-
#permissions_for(name) ⇒ Hash?
Get permission config for a tool.
-
#restricts_tools? ⇒ Boolean
Check if skill specifies a tool restriction.
Constructor Details
#initialize(file_path:, tools: nil, permissions: {}) ⇒ SkillState
Create a new SkillState
46 47 48 49 50 51 |
# File 'lib/swarm_memory/skill_state.rb', line 46 def initialize(file_path:, tools: nil, permissions: {}) @file_path = file_path @tools = tools&.map(&:to_s)&.freeze # Normalize and freeze = .freeze freeze # Make entire object immutable end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
23 24 25 |
# File 'lib/swarm_memory/skill_state.rb', line 23 def file_path @file_path end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
23 24 25 |
# File 'lib/swarm_memory/skill_state.rb', line 23 def end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
23 24 25 |
# File 'lib/swarm_memory/skill_state.rb', line 23 def tools @tools end |
Instance Method Details
#allows_tool?(name) ⇒ Boolean
Check if a specific tool is allowed by this skill
If the skill has no tool restriction (tools is nil), all tools are allowed. If the skill has a tool list, only tools in that list are allowed.
91 92 93 |
# File 'lib/swarm_memory/skill_state.rb', line 91 def allows_tool?(name) @tools.nil? || @tools.include?(name.to_s) end |
#permissions_for(name) ⇒ Hash?
Get permission config for a tool
Returns the permission configuration hash for a specific tool, or nil if no custom permissions are set.
113 114 115 |
# File 'lib/swarm_memory/skill_state.rb', line 113 def (name) [name.to_s] || [name.to_sym] end |
#restricts_tools? ⇒ Boolean
Check if skill specifies a tool restriction
Returns true if the skill has a NON-EMPTY tools array. Both nil and empty array mean "no restriction" (don't swap tools).
71 72 73 |
# File 'lib/swarm_memory/skill_state.rb', line 71 def restricts_tools? !@tools.nil? && !@tools.empty? end |