Class: Insika::Commands::WriteSystemFile

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

Overview

Control command: writes a GLOBAL system file into the SystemFileStore. Unlike write_agent_file (per agent), these files apply to ALL agents — the Prompt provider injects them before the individual identity. Takes effect on the next turn (hot). -> { file, updated_at }.

Instance Method Summary collapse

Constructor Details

#initialize(system_file_store:, event_stream:) ⇒ WriteSystemFile

Returns a new instance of WriteSystemFile.



12
13
14
15
# File 'lib/insika/commands/write_system_file.rb', line 12

def initialize(system_file_store:, event_stream:)
  @system_files = system_file_store
  @event_stream = event_stream
end

Instance Method Details

#call(command) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/insika/commands/write_system_file.rb', line 17

def call(command)
  p = AgentPayload.symbolize(command.payload)
  file = AgentPayload.presence(p[:file])
  raise Insika::ValidationError, "file is required" if file.nil?

  entry = @system_files.write(file, p[:content].to_s, create_only: !!p[:create_only])
  @event_stream.emit(Insika::Event.new(
                       type: :system_file_written, data: { file: file },
                       meta: { at: Time.now.utc.iso8601 }
                     ))
  { file: file, updated_at: entry["updated_at"] }
end