Class: Insika::SkillStore
- Inherits:
-
Object
- Object
- Insika::SkillStore
- Defined in:
- lib/insika/skill_store.rb
Overview
AUTHORED shared skills. Holds the complete SKILL.md (frontmatter + body) in the durable Store. The SkillCatalog overlays these skills on top of the on-disk ones (seed), with the Store winning — so editing/creating a skill in the Studio takes effect without a restart (via reload).
One record per skill in the ConfigStore (scope "skills"):
{ "content" => "<entire SKILL.md>",
"updated_at" => iso8601,
"history" => [ { "content" =>, "at" => }, ... ] }
The key is the skill's canonical name (the same as in the frontmatter). Versions like the AgentFileStore.
Constant Summary collapse
- SCOPE =
"skills"- HISTORY_MAX =
20
Instance Method Summary collapse
-
#all ⇒ Object
-> { name => content } of all authored skills.
-
#delete(name) ⇒ Object
-> bool (did it exist?).
-
#get(name) ⇒ Object
-> String | nil (complete SKILL.md).
-
#initialize(config_store:) ⇒ SkillStore
constructor
A new instance of SkillStore.
-
#names ⇒ Object
-> [String] names, lexicographic order.
-
#restore(name, index) ⇒ Object
Restores version
indexas the current content (a new write). -
#versions(name) ⇒ Object
-> [ { "content" =>, "at" => } ] most recent first.
-
#write(name, content, create_only: false) ⇒ Object
Writes (upsert).
Constructor Details
#initialize(config_store:) ⇒ SkillStore
Returns a new instance of SkillStore.
22 23 24 |
# File 'lib/insika/skill_store.rb', line 22 def initialize(config_store:) @cs = config_store end |
Instance Method Details
#all ⇒ Object
-> { name => content } of all authored skills.
35 36 37 |
# File 'lib/insika/skill_store.rb', line 35 def all @cs.keys(SCOPE).each_with_object({}) { |n, acc| acc[n] = get(n) } end |
#delete(name) ⇒ Object
-> bool (did it exist?).
51 |
# File 'lib/insika/skill_store.rb', line 51 def delete(name) = @cs.delete(SCOPE, name.to_s) |
#get(name) ⇒ Object
-> String | nil (complete SKILL.md).
27 28 29 |
# File 'lib/insika/skill_store.rb', line 27 def get(name) record(name)&.fetch("content", nil) end |
#names ⇒ Object
-> [String] names, lexicographic order.
32 |
# File 'lib/insika/skill_store.rb', line 32 def names = @cs.keys(SCOPE) |
#restore(name, index) ⇒ Object
Restores version index as the current content (a new write). -> Hash.
57 58 59 60 61 62 63 64 |
# File 'lib/insika/skill_store.rb', line 57 def restore(name, index) hist = versions(name) i = Integer(index) raise Insika::NotFoundError, "skill '#{name}' not found" unless record(name) raise Insika::ValidationError, "version #{index} does not exist" if i.negative? || i >= hist.length write(name, hist[i]["content"]) end |
#versions(name) ⇒ Object
-> [ { "content" =>, "at" => } ] most recent first.
54 |
# File 'lib/insika/skill_store.rb', line 54 def versions(name) = record(name)&.fetch("history", []) || [] |
#write(name, content, create_only: false) ⇒ Object
Writes (upsert). create_only refuses to overwrite. -> Hash (the stored record).
40 41 42 43 44 45 46 47 48 |
# File 'lib/insika/skill_store.rb', line 40 def write(name, content, create_only: false) key = name.to_s current = @cs.get(SCOPE, key) raise Insika::ValidationError, "skill '#{key}' already exists" if create_only && current rec = build_record(content.to_s, current) @cs.put(SCOPE, key, rec) rec end |