Class: ClaudeMemory::Commands::RecoverCommand

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

Overview

Recovers from stuck operations by resetting them

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) ⇒ Object



7
8
9
10
11
12
13
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
46
47
48
49
50
51
52
53
54
55
# File 'lib/claude_memory/commands/recover_command.rb', line 7

def call(args)
  opts = parse_options(args, {operation: nil, scope: nil}) do |o|
    OptionParser.new do |parser|
      parser.banner = "Usage: claude-memory recover [options]"
      parser.on("--operation TYPE", "Filter by operation type") { |v| o[:operation] = v }
      parser.on("--scope SCOPE", "Filter by scope (global/project)") { |v| o[:scope] = v }
    end
  end
  return 1 if opts.nil?

  manager = Store::StoreManager.new

  total_reset = 0

  # Reset stuck operations in global database
  if opts[:scope].nil? || opts[:scope] == "global"
    if File.exist?(manager.global_db_path)
      count = reset_stuck_operations(
        manager.global_store,
        "global",
        opts[:operation]
      )
      total_reset += count
    end
  end

  # Reset stuck operations in project database
  if opts[:scope].nil? || opts[:scope] == "project"
    if File.exist?(manager.project_db_path)
      count = reset_stuck_operations(
        manager.project_store,
        "project",
        opts[:operation]
      )
      total_reset += count
    end
  end

  manager.close

  if total_reset.zero?
    stdout.puts "No stuck operations found."
  else
    stdout.puts "Reset #{total_reset} stuck operation(s)."
    stdout.puts "You can now re-run the failed operation."
  end

  0
end