Class: Riffer::Skills::Context
- Inherits:
-
Object
- Object
- Riffer::Skills::Context
- Defined in:
- lib/riffer/skills/context.rb
Overview
Skills context for an agent generation cycle — coordinates discovery, activation, and prompt rendering, caching activations to avoid redundant backend reads. Exposed to tools via context.skills.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
The skill adapter used for this context.
-
#on_activate ⇒ Object
writeonly
Optional callback invoked when a skill is first activated.
-
#skills ⇒ Object
readonly
Skill catalog indexed by name.
Instance Method Summary collapse
-
#activate(name) ⇒ Object
Activates a skill by name.
-
#activated?(name) ⇒ Boolean
Returns whether a skill has been activated.
-
#initialize(backend:, skills:, adapter:) ⇒ Context
constructor
– : (backend: Riffer::Skills::Backend, skills: Hash[String, Riffer::Skills::Frontmatter], adapter: Riffer::Skills::Adapter) -> void.
-
#system_prompt ⇒ Object
Returns the complete skills section for the system prompt — the catalog plus any pre-activated skill bodies.
Constructor Details
#initialize(backend:, skills:, adapter:) ⇒ Context
– : (backend: Riffer::Skills::Backend, skills: Hash[String, Riffer::Skills::Frontmatter], adapter: Riffer::Skills::Adapter) -> void
22 23 24 25 26 27 |
# File 'lib/riffer/skills/context.rb', line 22 def initialize(backend:, skills:, adapter:) @backend = backend @skills = skills @adapter = adapter @activated = {} #: Hash[String, String] end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
The skill adapter used for this context.
15 16 17 |
# File 'lib/riffer/skills/context.rb', line 15 def adapter @adapter end |
#on_activate=(value) ⇒ Object (writeonly)
Optional callback invoked when a skill is first activated.
18 19 20 |
# File 'lib/riffer/skills/context.rb', line 18 def on_activate=(value) @on_activate = value end |
#skills ⇒ Object (readonly)
Skill catalog indexed by name.
12 13 14 |
# File 'lib/riffer/skills/context.rb', line 12 def skills @skills end |
Instance Method Details
#activate(name) ⇒ Object
Activates a skill by name. Returns the cached body on re-activation.
Raises Riffer::ArgumentError if the skill is not in the catalog.
– : (String) -> String
35 36 37 38 39 40 41 |
# File 'lib/riffer/skills/context.rb', line 35 def activate(name) raise Riffer::ArgumentError, "Unknown skill: '#{name}'" unless skills.key?(name) return @activated[name] if @activated.key?(name) @activated[name] = @backend.read_skill(name) @on_activate&.call(name) @activated[name] end |
#activated?(name) ⇒ Boolean
Returns whether a skill has been activated.
– : (String) -> bool
47 48 49 |
# File 'lib/riffer/skills/context.rb', line 47 def activated?(name) @activated.key?(name) end |
#system_prompt ⇒ Object
Returns the complete skills section for the system prompt — the catalog plus any pre-activated skill bodies. – : () -> String
55 56 57 58 59 60 61 |
# File 'lib/riffer/skills/context.rb', line 55 def system_prompt available = available_skills parts = [] #: Array[String] parts << @adapter.render_catalog(available) unless available.empty? @activated.each_value { |body| parts << body } parts.join("\n\n") end |