Class: Llmemory::Cli::Commands::Maintain

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

Overview

Runs the cognitive maintenance pass for a user: reflect -> mine skills -> expire. Each step is isolated; failures are reported, not fatal.

Instance Method Summary collapse

Methods inherited from Base

#parse_options, #run

Instance Method Details

#execute(argv, _opts) ⇒ Object



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/maintain.rb', line 19

def execute(argv, _opts)
  user_id = argv.first
  unless user_id
    $stderr.puts "Usage: llmemory maintain USER_ID [--[no-]reflect] [--mine-skills] [--[no-]expire] [--window N] [--store TYPE]"
    exit 1
  end

  opts = {
    episodic: Llmemory::LongTerm::Episodic::Memory.new(user_id: user_id, storage: episodic_storage(@store_type)),
    procedural: Llmemory::LongTerm::Procedural::Memory.new(user_id: user_id, storage: procedural_storage(@store_type)),
    semantic: build_semantic(user_id),
    reflect: @reflect.nil? ? true : @reflect,
    expire: @expire.nil? ? true : @expire
  }
  opts[:mine_skills] = @mine unless @mine.nil?
  opts[:reflection_window] = @window if @window

  report = Llmemory::Maintenance::CognitivePass.run!(user_id, **opts)
  print_report(user_id, report)
end

#option_parser(parser) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/llmemory/cli/commands/maintain.rb', line 11

def option_parser(parser)
  parser.on("--[no-]reflect", "Distill insights from recent episodes (default: on)") { |v| @reflect = v }
  parser.on("--mine-skills", "Mine and register skills from episodes (default: config)") { @mine = true }
  parser.on("--[no-]expire", "Soft-archive entries past their TTL (default: on)") { |v| @expire = v }
  parser.on("--window N", Integer, "Episodes to reflect over (default 10)") { |v| @window = v }
  parser.on("--store TYPE", "Storage type (memory|file|postgres|active_record)") { |v| @store_type = v }
end