Class: Llmemory::Cli::Commands::Episodic

Inherits:
Base
  • Object
show all
Defined in:
lib/llmemory/cli/commands/episodic.rb

Instance Method Summary collapse

Methods inherited from Base

#parse_options, #run

Instance Method Details

#execute(argv, _opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/llmemory/cli/commands/episodic.rb', line 14

def execute(argv, _opts)
  user_id = argv.first
  unless user_id
    $stderr.puts "Usage: llmemory episodes USER_ID [--limit N] [--store TYPE]"
    exit 1
  end

  storage = episodic_storage(@store_type)
  episodes = storage.list_episodes(user_id, limit: @limit)

  if episodes.empty?
    puts "No episodes for user #{user_id}."
    return
  end

  episodes.each do |e|
    id = e[:id] || e["id"]
    summary = e[:summary] || e["summary"]
    outcome = e[:outcome] || e["outcome"]
    importance = e[:importance] || e["importance"]
    steps = e[:steps] || e["steps"] || []
    puts "[#{id}] (importance: #{importance}; outcome: #{outcome || 'n/a'}) #{summary}"
    puts "  steps: #{Array(steps).size}"
  end
end

#option_parser(parser) ⇒ Object



9
10
11
12
# File 'lib/llmemory/cli/commands/episodic.rb', line 9

def option_parser(parser)
  parser.on("--limit N", Integer, "Max number of episodes (newest first)") { |v| @limit = v }
  parser.on("--store TYPE", "Storage type (memory|file|postgres|active_record)") { |v| @store_type = v }
end