Class: Rubino::CLI::MemoryCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/rubino/cli/memory_command.rb

Overview

Subcommands for managing persistent memories

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rubino/cli/memory_command.rb', line 12

def self.exit_on_failure?
  true
end

.render(memory, ui:) ⇒ Object

ONE fact-details rendering for both surfaces (#184): the CLI verb above and the in-chat ‘/memory show <id>` (Commands::Executor).



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubino/cli/memory_command.rb', line 55

def self.render(memory, ui:)
  ui.info("ID: #{memory[:id]}")
  ui.info("Kind: #{memory[:kind]}")
  ui.info("Confidence: #{memory[:confidence]}")
  ui.info("Created: #{memory[:created_at]}")
  # The temporal chain (#88): a soft-retired fact shows when it stopped
  # being true and which fact replaced it.
  if memory[:valid_to]
    ui.info("Retired: #{memory[:valid_to]}")
    ui.info("Superseded by: #{memory[:superseded_by]}") if memory[:superseded_by]
  end
  ui.separator
  ui.info(memory[:content])
end

.render_active_backend(ui:) ⇒ Object

ONE backend summary for both surfaces (#184): the CLI ‘memory backend` verb and the in-chat `/memory backend`.



109
110
111
112
113
# File 'lib/rubino/cli/memory_command.rb', line 109

def self.render_active_backend(ui:)
  active = Rubino.configuration.dig("memory", "backend") || Memory::Backends::DEFAULT_NAME
  ui.info("Active backend: #{active}")
  ui.info("Available: #{Memory::Backends.names.join(", ")}")
end

.retired_marker(memory) ⇒ Object

‘–all` surfaces soft-retired rows next to live ones; without a flag they were indistinguishable and the supersession chain needed a `show` per id (#161). Marks a tombstone with its retirement date and, when known, the short id of the fact that replaced it. A class method so the in-chat `/memory –all` table (#184) speaks the same dialect.



99
100
101
102
103
104
105
# File 'lib/rubino/cli/memory_command.rb', line 99

def self.retired_marker(memory)
  return "" unless memory[:valid_to]

  marker = " (retired #{memory[:valid_to][0..9]}"
  marker += "#{memory[:superseded_by][0..7]}" if memory[:superseded_by]
  "#{marker})"
end

Instance Method Details

#backend(name = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rubino/cli/memory_command.rb', line 80

def backend(name = nil)
  return show_backend if name.nil?

  unless Memory::Backends.registered?(name)
    Rubino.ui.error(
      "Unknown memory backend: #{name}. Available: #{Memory::Backends.names.join(", ")}"
    )
    return
  end

  Config::Writer.new(config_path: config_path).set("memory.backend", name)
  Rubino.ui.success("memory.backend = #{name}")
end

#delete(id) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/rubino/cli/memory_command.rb', line 71

def delete(id)
  if backend_store.delete(id)
    Rubino.ui.success("Memory deleted: #{id}")
  else
    Rubino.ui.error("memory not found: #{id}")
  end
end

#listObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubino/cli/memory_command.rb', line 21

def list
  Rubino.ensure_database_ready!
  memories = backend_store.list(kind: options[:kind], limit: options[:limit],
                                include_retired: options[:all])

  if memories.empty?
    Rubino.ui.info("No memories found.")
    return
  end

  rows = memories.map do |m|
    [m[:id][0..7], m[:kind], "#{m[:content][0..60]}#{self.class.retired_marker(m)}", m[:created_at]]
  end

  Rubino.ui.table(
    headers: %w[ID Kind Content Created],
    rows: rows
  )
end

#show(id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rubino/cli/memory_command.rb', line 42

def show(id)
  memory = backend_store.find(id)

  if memory.nil?
    Rubino.ui.error("memory not found: #{id}")
    return
  end

  self.class.render(memory, ui: Rubino.ui)
end