Class: Aidp::Execute::Checkpoint

Inherits:
Object
  • Object
show all
Includes:
RescueLogging
Defined in:
lib/aidp/execute/checkpoint.rb

Overview

Manages periodic checkpoints during work loop execution Tracks progress metrics, code quality, and task completion

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RescueLogging

__log_rescue_impl, log_rescue, #log_rescue

Constructor Details

#initialize(project_dir) ⇒ Checkpoint

Returns a new instance of Checkpoint.



17
18
19
20
21
22
# File 'lib/aidp/execute/checkpoint.rb', line 17

def initialize(project_dir)
  @project_dir = project_dir
  @checkpoint_file = File.join(project_dir, ".aidp", "checkpoint.yml")
  @history_file = File.join(project_dir, ".aidp", "checkpoint_history.jsonl")
  ensure_checkpoint_directory
end

Instance Attribute Details

#checkpoint_fileObject (readonly)

Returns the value of attribute checkpoint_file.



15
16
17
# File 'lib/aidp/execute/checkpoint.rb', line 15

def checkpoint_file
  @checkpoint_file
end

#history_fileObject (readonly)

Returns the value of attribute history_file.



15
16
17
# File 'lib/aidp/execute/checkpoint.rb', line 15

def history_file
  @history_file
end

#project_dirObject (readonly)

Returns the value of attribute project_dir.



15
16
17
# File 'lib/aidp/execute/checkpoint.rb', line 15

def project_dir
  @project_dir
end

Instance Method Details

#checkpoint_history(limit: 100) ⇒ Object

Get checkpoint history for analysis



47
48
49
50
51
52
53
54
55
# File 'lib/aidp/execute/checkpoint.rb', line 47

def checkpoint_history(limit: 100)
  return [] unless File.exist?(@history_file)

  File.readlines(@history_file).last(limit).map do |line|
    JSON.parse(line, symbolize_names: true)
  end
rescue JSON::ParserError
  []
end

#clearObject

Clear all checkpoint data



74
75
76
77
# File 'lib/aidp/execute/checkpoint.rb', line 74

def clear
  File.delete(@checkpoint_file) if File.exist?(@checkpoint_file)
  File.delete(@history_file) if File.exist?(@history_file)
end

#latest_checkpointObject

Get the latest checkpoint data



41
42
43
44
# File 'lib/aidp/execute/checkpoint.rb', line 41

def latest_checkpoint
  return nil unless File.exist?(@checkpoint_file)
  YAML.safe_load_file(@checkpoint_file, permitted_classes: [Date, Time, Symbol], aliases: true)
end

#progress_summaryObject

Get progress summary comparing current state to previous checkpoints



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aidp/execute/checkpoint.rb', line 58

def progress_summary
  latest = latest_checkpoint
  return nil unless latest

  history = checkpoint_history(limit: 10)
  previous = history[-2] if history.size > 1

  {
    current: latest,
    previous: previous,
    trends: calculate_trends(history),
    quality_score: calculate_quality_score(latest[:metrics])
  }
end

#record_checkpoint(step_name, iteration, metrics = {}) ⇒ Object

Record a checkpoint during work loop iteration



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aidp/execute/checkpoint.rb', line 25

def record_checkpoint(step_name, iteration, metrics = {})
  checkpoint_data = {
    step_name: step_name,
    iteration: iteration,
    timestamp: Time.now.iso8601,
    metrics: collect_metrics.merge(metrics),
    status: determine_status(metrics)
  }

  save_checkpoint(checkpoint_data)
  append_to_history(checkpoint_data)

  checkpoint_data
end