Class: Aidp::Harness::State::Persistence

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/harness/state/persistence.rb

Overview

Handles file I/O and persistence for state management

Instance Method Summary collapse

Constructor Details

#initialize(project_dir, mode) ⇒ Persistence

Returns a new instance of Persistence.



11
12
13
14
15
16
17
18
# File 'lib/aidp/harness/state/persistence.rb', line 11

def initialize(project_dir, mode)
  @project_dir = project_dir
  @mode = mode
  @state_dir = File.join(project_dir, ".aidp", "harness")
  @state_file = File.join(@state_dir, "#{mode}_state.json")
  @lock_file = File.join(@state_dir, "#{mode}_state.lock")
  ensure_state_directory
end

Instance Method Details

#clear_stateObject



46
47
48
49
50
51
52
# File 'lib/aidp/harness/state/persistence.rb', line 46

def clear_state
  return if test_mode?

  with_lock do
    File.delete(@state_file) if File.exist?(@state_file)
  end
end

#has_state?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/aidp/harness/state/persistence.rb', line 20

def has_state?
  return false if test_mode?
  File.exist?(@state_file)
end

#load_stateObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aidp/harness/state/persistence.rb', line 25

def load_state
  return {} if test_mode? || !has_state?

  with_lock do
    content = File.read(@state_file)
    JSON.parse(content, symbolize_names: true)
  rescue JSON::ParserError => e
    warn "Failed to parse state file: #{e.message}"
    {}
  end
end

#save_state(state_data) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/aidp/harness/state/persistence.rb', line 37

def save_state(state_data)
  return if test_mode?

  with_lock do
     = (state_data)
    write_atomically()
  end
end