Class: Llmemory::Cli::Commands::LongTerm::Resources

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

Instance Method Summary collapse

Methods inherited from Base

#parse_options, #run

Instance Method Details

#execute(argv, _opts) ⇒ Object



15
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/resources.rb', line 15

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

  storage = file_based_storage(@store_type)
  resources = storage.list_resources(user_id: user_id, limit: @limit)

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

  resources.each do |r|
    id = r[:id] || r["id"]
    text = (r[:text] || r["text"]).to_s
    text = text[0, 150] + "..." if text.length > 150
    created = r[:created_at] || r["created_at"]
    puts "#{id}: #{text} (#{created})"
  end
end

#option_parser(parser) ⇒ Object



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

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