Class: Llmemory::Cli::Commands::LongTerm::Nodes

Inherits:
Base
  • Object
show all
Defined in:
lib/llmemory/cli/commands/long_term/nodes.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/nodes.rb', line 16

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

  storage = graph_based_storage(@store_type)
  nodes = storage.list_nodes(user_id, entity_type: @entity_type, limit: @limit)

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

  nodes.each do |n|
    id = n.respond_to?(:id) ? n.id : n[:id]
    type = n.respond_to?(:entity_type) ? n.entity_type : n[:entity_type]
    name = n.respond_to?(:name) ? n.name : n[:name]
    puts "#{id} [#{type}] #{name}"
  end
end

#option_parser(parser) ⇒ Object



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

def option_parser(parser)
  parser.on("--type TYPE", "Filter by entity type") { |v| @entity_type = v }
  parser.on("--limit N", Integer, "Max number of nodes") { |v| @limit = v }
  parser.on("--store TYPE", "Storage type (memory, active_record)") { |v| @store_type = v }
end