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.



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

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")
  @run_loop_file = File.join(project_dir, ".aidp", "run_loop_started_at")
  ensure_checkpoint_directory
end

Instance Attribute Details

#checkpoint_file ⇒ Object (readonly)

Returns the value of attribute checkpoint_file.



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

def checkpoint_file
  @checkpoint_file
end

#history_file ⇒ Object (readonly)

Returns the value of attribute history_file.



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

def history_file
  @history_file
end

#project_dir ⇒ Object (readonly)

Returns the value of attribute project_dir.



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

def project_dir
  @project_dir
end

Instance Method Details

#checkpoint_history(limit: 100) ⇒ Object

Get checkpoint history for analysis



53
54
55
56
57
58
59
60
61
# File 'lib/aidp/execute/checkpoint.rb', line 53

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

#clear ⇒ Object

Clear all checkpoint data



80
81
82
83
# File 'lib/aidp/execute/checkpoint.rb', line 80

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

#latest_checkpoint ⇒ Object

Get the latest checkpoint data



46
47
48
49
50
# File 'lib/aidp/execute/checkpoint.rb', line 46

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

Get progress summary comparing current state to previous checkpoints



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aidp/execute/checkpoint.rb', line 64

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aidp/execute/checkpoint.rb', line 27

def record_checkpoint(step_name, iteration, metrics = {})
  run_loop_started_at = read_run_loop_started_at || Time.now.iso8601
  write_run_loop_started_at(run_loop_started_at) if iteration == 1
  checkpoint_data = {
    step_name: step_name,
    iteration: iteration,
    timestamp: Time.now.iso8601,
    run_loop_started_at: run_loop_started_at,
    metrics: collect_metrics.merge(metrics),
    status: determine_status(metrics)
  }

  save_checkpoint(checkpoint_data)
  append_to_history(checkpoint_data)

  checkpoint_data
end