Class: ClaudeMemory::Commands::RestoreCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/claude_memory/commands/restore_command.rb

Overview

One-time recovery for facts that were superseded because of an obsolete single-value predicate classification. See Sweep::Maintenance#restore_multi_value_supersessions for the algorithm and Jaccard heuristic.

Instance Attribute Summary

Attributes inherited from BaseCommand

#stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ClaudeMemory::Commands::BaseCommand

Instance Method Details

#call(args) ⇒ Integer

Returns exit code (0 for success, 1 for failure).

Parameters:

  • args (Array<String>)

    command line arguments (–predicate, –scope, –dry-run)

Returns:

  • (Integer)

    exit code (0 for success, 1 for failure)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/claude_memory/commands/restore_command.rb', line 14

def call(args)
  opts = parse_options(args, {predicate: nil, scope: "project", dry_run: false}) do |o|
    OptionParser.new do |parser|
      parser.banner = "Usage: claude-memory restore --predicate NAME [options]"
      parser.on("--predicate NAME", "Predicate to restore (e.g. uses_framework)") { |v| o[:predicate] = v }
      parser.on("--scope SCOPE", %w[project global], "Database scope (default: project)") { |v| o[:scope] = v }
      parser.on("--dry-run", "Show what would be restored without writing") { o[:dry_run] = true }
    end
  end
  return 1 if opts.nil?

  return failure("--predicate required (e.g. --predicate uses_framework)") if opts[:predicate].nil?

  manager = ClaudeMemory::Store::StoreManager.new
  store = manager.store_for_scope(opts[:scope])

  begin
    result = Sweep::Maintenance.new(store).restore_multi_value_supersessions(
      predicate: opts[:predicate],
      dry_run: opts[:dry_run]
    )
  rescue ArgumentError => e
    stderr.puts e.message
    manager.close
    return 1
  ensure
    manager.close
  end

  print_result(opts, result)
  0
end