Class: Aidp::AutoUpdate::Checkpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/auto_update/checkpoint.rb

Overview

Aggregate root representing a complete state snapshot for restart recovery

Constant Summary collapse

SCHEMA_VERSION =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode:, checkpoint_id: SecureRandom.uuid, created_at: Time.now, aidp_version: Aidp::VERSION, watch_state: nil, metadata: {}, checksum: nil) ⇒ Checkpoint

Returns a new instance of Checkpoint.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aidp/auto_update/checkpoint.rb', line 18

def initialize(
  mode:, checkpoint_id: SecureRandom.uuid,
  created_at: Time.now,
  aidp_version: Aidp::VERSION,
  watch_state: nil,
  metadata: {},
  checksum: nil
)
  @checkpoint_id = checkpoint_id
  @created_at = created_at
  @aidp_version = aidp_version
  @mode = validate_mode(mode)
  @watch_state = watch_state
  @metadata = .merge()
  @checksum = checksum || compute_checksum
end

Instance Attribute Details

#aidp_versionObject (readonly)

Returns the value of attribute aidp_version.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def aidp_version
  @aidp_version
end

#checkpoint_idObject (readonly)

Returns the value of attribute checkpoint_id.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def checkpoint_id
  @checkpoint_id
end

#checksumObject (readonly)

Returns the value of attribute checksum.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def checksum
  @checksum
end

#created_atObject (readonly)

Returns the value of attribute created_at.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def created_at
  @created_at
end

#metadataObject (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def 
  @metadata
end

#modeObject (readonly)

Returns the value of attribute mode.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def mode
  @mode
end

#watch_stateObject (readonly)

Returns the value of attribute watch_state.



13
14
15
# File 'lib/aidp/auto_update/checkpoint.rb', line 13

def watch_state
  @watch_state
end

Class Method Details

.from_h(hash) ⇒ Checkpoint

Create checkpoint from hash (deserialization)

Parameters:

  • hash (Hash)

    Serialized checkpoint data

Returns:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aidp/auto_update/checkpoint.rb', line 56

def self.from_h(hash)
  new(
    checkpoint_id: hash[:checkpoint_id] || hash["checkpoint_id"],
    created_at: Time.parse(hash[:created_at] || hash["created_at"]),
    aidp_version: hash[:aidp_version] || hash["aidp_version"],
    mode: hash[:mode] || hash["mode"],
    watch_state: hash[:watch_state] || hash["watch_state"],
    metadata: hash[:metadata] || hash["metadata"] || {},
    checksum: hash[:checksum] || hash["checksum"]
  )
end

.from_watch_runner(runner) ⇒ Checkpoint

Create checkpoint from current watch mode state

Parameters:

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aidp/auto_update/checkpoint.rb', line 38

def self.from_watch_runner(runner)
  new(
    mode: "watch",
    watch_state: {
      repository: runner.instance_variable_get(:@repository_client).full_repo,
      interval: runner.instance_variable_get(:@interval),
      provider_name: runner.instance_variable_get(:@plan_processor).instance_variable_get(:@plan_generator).instance_variable_get(:@provider_name),
      persona: nil, # Not currently tracked in runner
      safety_config: runner.instance_variable_get(:@safety_checker).instance_variable_get(:@config),
      worktree_context: capture_worktree_context,
      state_store_snapshot: runner.instance_variable_get(:@state_store).send(:state)
    }
  )
end

Instance Method Details

#compatible_version?Boolean

Check if checkpoint is compatible with current Aidp version

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
105
106
# File 'lib/aidp/auto_update/checkpoint.rb', line 97

def compatible_version?
  # Allow restoring from same major.minor version
  checkpoint_ver = Gem::Version.new(@aidp_version)
  current_ver = Gem::Version.new(Aidp::VERSION)

  checkpoint_ver.segments[0] == current_ver.segments[0] &&
    checkpoint_ver.segments[1] == current_ver.segments[1]
rescue ArgumentError
  false
end

#to_hHash

Convert to hash for serialization

Returns:

  • (Hash)


70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/aidp/auto_update/checkpoint.rb', line 70

def to_h
  {
    schema_version: SCHEMA_VERSION,
    checkpoint_id: @checkpoint_id,
    created_at: @created_at.utc.iso8601(6), # Preserve microsecond precision
    aidp_version: @aidp_version,
    mode: @mode,
    watch_state: @watch_state,
    metadata: @metadata,
    checksum: @checksum
  }
end

#valid?Boolean

Verify checkpoint integrity

Returns:

  • (Boolean)


85
86
87
# File 'lib/aidp/auto_update/checkpoint.rb', line 85

def valid?
  @checksum == compute_checksum
end

#watch_mode?Boolean

Check if checkpoint is for watch mode

Returns:

  • (Boolean)


91
92
93
# File 'lib/aidp/auto_update/checkpoint.rb', line 91

def watch_mode?
  @mode == "watch"
end