Class: Llmemory::Cli::Commands::LongTerm::Facts

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

Instance Method Summary collapse

Methods inherited from Base

#parse_options, #run

Instance Method Details

#execute(argv, _opts) ⇒ Object



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

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

  storage = file_based_storage(@store_type)
  items = storage.list_items(user_id: user_id, category: @category, limit: @limit)

  if items.empty?
    puts "No facts found for user #{user_id}."
    return
  end

  items.each do |i|
    cat = i[:category] || i["category"]
    content = (i[:content] || i["content"]).to_s
    created = i[:created_at] || i["created_at"]
    puts "[#{cat}] #{content} (#{created})"
  end
end

#option_parser(parser) ⇒ Object



10
11
12
13
14
# File 'lib/llmemory/cli/commands/long_term/facts.rb', line 10

def option_parser(parser)
  parser.on("--category CATEGORY", "Filter by category") { |v| @category = v }
  parser.on("--limit N", Integer, "Max number of items") { |v| @limit = v }
  parser.on("--store TYPE", "Storage type") { |v| @store_type = v }
end