Class: Aidp::AutoUpdate::Checkpoint
- Inherits:
-
Object
- Object
- Aidp::AutoUpdate::Checkpoint
- 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
-
#aidp_version ⇒ Object
readonly
Returns the value of attribute aidp_version.
-
#checkpoint_id ⇒ Object
readonly
Returns the value of attribute checkpoint_id.
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#watch_state ⇒ Object
readonly
Returns the value of attribute watch_state.
Class Method Summary collapse
-
.from_h(hash) ⇒ Checkpoint
Create checkpoint from hash (deserialization).
-
.from_watch_runner(runner) ⇒ Checkpoint
Create checkpoint from current watch mode state.
Instance Method Summary collapse
-
#compatible_version? ⇒ Boolean
Check if checkpoint is compatible with current Aidp version.
-
#initialize(mode:, checkpoint_id: SecureRandom.uuid, created_at: Time.now, aidp_version: Aidp::VERSION, watch_state: nil, metadata: {}, checksum: nil) ⇒ Checkpoint
constructor
A new instance of Checkpoint.
-
#to_h ⇒ Hash
Convert to hash for serialization.
-
#valid? ⇒ Boolean
Verify checkpoint integrity.
-
#watch_mode? ⇒ Boolean
Check if checkpoint is for watch mode.
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_version ⇒ Object (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_id ⇒ Object (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 |
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
13 14 15 |
# File 'lib/aidp/auto_update/checkpoint.rb', line 13 def checksum @checksum end |
#created_at ⇒ Object (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 |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/aidp/auto_update/checkpoint.rb', line 13 def @metadata end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
13 14 15 |
# File 'lib/aidp/auto_update/checkpoint.rb', line 13 def mode @mode end |
#watch_state ⇒ Object (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)
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
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
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_h ⇒ Hash
Convert to hash for serialization
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
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
91 92 93 |
# File 'lib/aidp/auto_update/checkpoint.rb', line 91 def watch_mode? @mode == "watch" end |