Class: Insika::SystemFileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/system_file_store.rb

Overview

GLOBAL system files. These are prompts/rules that apply to ALL agents in the deploy — the "house" above each BIA's individual identity. Unlike the AgentFileStore (per agent), here there is no tenant: one record per file in the ConfigStore (scope "system_files").

Context::Providers::Prompt reads these files and injects them BEFORE the per-agent identity, for every turn. With no system files (empty store), the prompt is byte-for-byte the one from before (parity preserved) — the global injection only exists when the operator authors something here.

Record per file:

{ "content" => str, "updated_at" => iso8601,
"history" => [ { "content" => str, "at" => iso8601 }, ... ] }

A write versions (same contract as AgentFileStore): the previous content goes into history (most recent first), capped at HISTORY_MAX; restoring is a new write (linear history, no destructive "time travel").

Constant Summary collapse

SCOPE =
"system_files"
HISTORY_MAX =
20

Instance Method Summary collapse

Constructor Details

#initialize(config_store:) ⇒ SystemFileStore

Returns a new instance of SystemFileStore.



27
28
29
# File 'lib/insika/system_file_store.rb', line 27

def initialize(config_store:)
  @cs = config_store
end

Instance Method Details

#delete(filename) ⇒ Object

-> bool (did it exist?).



58
59
60
# File 'lib/insika/system_file_store.rb', line 58

def delete(filename)
  @cs.delete(SCOPE, filename.to_s)
end

#listObject

-> [String] file names, lexicographic order.



37
38
39
# File 'lib/insika/system_file_store.rb', line 37

def list
  @cs.keys(SCOPE).sort
end

#read(filename) ⇒ Object

-> String | nil (current content).



32
33
34
# File 'lib/insika/system_file_store.rb', line 32

def read(filename)
  entry(filename.to_s)&.fetch("content", nil)
end

#restore(filename, index) ⇒ Object

Restores version index from history as the current content (a new write). -> Hash (entry) | raises if index invalid / file nonexistent.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/insika/system_file_store.rb', line 69

def restore(filename, index)
  name = filename.to_s
  current = entry(name)
  raise Insika::NotFoundError, "system file '#{name}' not found" unless current

  hist = current.fetch("history", [])
  i = Integer(index)
  raise Insika::ValidationError, "version #{index} does not exist" if i.negative? || i >= hist.length

  write(name, hist[i]["content"])
end

#versions(filename) ⇒ Object

-> [ { "content" =>, "at" => } ] older versions, most recent first.



63
64
65
# File 'lib/insika/system_file_store.rb', line 63

def versions(filename)
  entry(filename.to_s)&.fetch("history", []) || []
end

#write(filename, content, create_only: false) ⇒ Object

Writes (upsert). create_only: refuses to overwrite. Versions the previous one into history. -> Hash (the stored entry).



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/insika/system_file_store.rb', line 43

def write(filename, content, create_only: false)
  name = filename.to_s
  raise Insika::ValidationError, "file is required" if name.empty?

  current = entry(name)
  if create_only && current
    raise Insika::ValidationError, "system file '#{name}' already exists"
  end

  built = build_entry(content.to_s, current)
  @cs.put(SCOPE, name, built)
  built
end