Class: Aidp::Watch::StateStore
- Inherits:
-
Object
- Object
- Aidp::Watch::StateStore
- Defined in:
- lib/aidp/watch/state_store.rb
Overview
Persists watch mode progress for each repository/issue pair. Used to avoid re-processing plan/build triggers and to retain generated plan context between runs.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#auto_pr_cap_reached?(pr_number, cap:) ⇒ Boolean
Check if an auto PR has reached the iteration cap.
-
#auto_pr_data(pr_number) ⇒ Hash?
Get full auto PR data.
-
#auto_pr_iteration_count(pr_number) ⇒ Integer
Get the current iteration count for an auto PR.
- #blocking_status(issue_number) ⇒ Object
- #build_status(issue_number) ⇒ Object
- #change_request_data(pr_number) ⇒ Object
-
#change_request_processed?(pr_number) ⇒ Boolean
Change request tracking methods.
-
#ci_fix_completed?(pr_number) ⇒ Boolean
CI fix tracking methods.
- #ci_fix_data(pr_number) ⇒ Object
-
#complete_auto_pr(pr_number, data = {}) ⇒ Object
Mark an auto PR as completed (ready for human review).
-
#detection_comment_posted?(detection_key) ⇒ Boolean
Detection comment tracking methods (issue #280).
-
#find_build_by_pr(pr_number) ⇒ Hash?
Find the build/workstream metadata associated with a PR URL This is used to map change-request PRs back to their originating issues/worktrees.
-
#initialize(project_dir:, repository:) ⇒ StateStore
constructor
A new instance of StateStore.
-
#mark_reaction_processed(comment_id, reaction_id) ⇒ Object
Mark a reaction as processed.
- #parent_issue(sub_issue_number) ⇒ Object
- #plan_data(issue_number) ⇒ Object
- #plan_iteration_count(issue_number) ⇒ Object
- #plan_processed?(issue_number) ⇒ Boolean
-
#processed_reaction_ids(comment_id) ⇒ Array<Integer>
Get IDs of reactions already processed for a comment.
-
#project_item_id(issue_number) ⇒ Object
Project tracking methods.
- #project_sync_data(issue_number) ⇒ Object
-
#record_auto_pr_iteration(pr_number, data = {}) ⇒ Integer
Record an auto PR iteration.
- #record_build_status(issue_number, status:, details: {}) ⇒ Object
- #record_change_request(pr_number, data) ⇒ Object
- #record_ci_fix(pr_number, data) ⇒ Object
- #record_detection_comment(detection_key, timestamp:) ⇒ Object
- #record_plan(issue_number, data) ⇒ Object
- #record_project_item_id(issue_number, item_id) ⇒ Object
- #record_project_sync(issue_number, data) ⇒ Object
- #record_review(pr_number, data) ⇒ Object
- #record_sub_issues(parent_number, sub_issue_numbers) ⇒ Object
- #reset_change_request_state(pr_number) ⇒ Object
- #review_data(pr_number) ⇒ Object
-
#review_processed?(pr_number) ⇒ Boolean
Review tracking methods.
-
#sub_issues(parent_number) ⇒ Object
Sub-issue tracking methods.
-
#track_comment_for_feedback(comment_id:, processor_type:, number:) ⇒ Object
Track a comment for feedback collection.
-
#tracked_comments ⇒ Array<Hash>
Get all tracked comments with their metadata for feedback collection.
-
#workstream_for_issue(issue_number) ⇒ Hash?
Retrieve workstream metadata for a given issue.
Constructor Details
#initialize(project_dir:, repository:) ⇒ StateStore
Returns a new instance of StateStore.
15 16 17 18 19 20 |
# File 'lib/aidp/watch/state_store.rb', line 15 def initialize(project_dir:, repository:) @project_dir = project_dir @repository = repository @path = File.join(project_dir, ".aidp", "watch", "#{sanitize_repository(repository)}.yml") ensure_directory end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/aidp/watch/state_store.rb', line 13 def path @path end |
Instance Method Details
#auto_pr_cap_reached?(pr_number, cap:) ⇒ Boolean
Check if an auto PR has reached the iteration cap
338 339 340 |
# File 'lib/aidp/watch/state_store.rb', line 338 def auto_pr_cap_reached?(pr_number, cap:) auto_pr_iteration_count(pr_number) >= cap end |
#auto_pr_data(pr_number) ⇒ Hash?
Get full auto PR data
295 296 297 |
# File 'lib/aidp/watch/state_store.rb', line 295 def auto_pr_data(pr_number) auto_prs[pr_number.to_s] end |
#auto_pr_iteration_count(pr_number) ⇒ Integer
Get the current iteration count for an auto PR
286 287 288 289 290 |
# File 'lib/aidp/watch/state_store.rb', line 286 def auto_pr_iteration_count(pr_number) data = auto_prs[pr_number.to_s] return 0 unless data data["iteration"] || 0 end |
#blocking_status(issue_number) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/aidp/watch/state_store.rb', line 388 def blocking_status(issue_number) # Check if this issue is blocked by any open sub-issues sub_issue_numbers = sub_issues(issue_number) return {blocked: false, blockers: []} if sub_issue_numbers.empty? { blocked: true, blockers: sub_issue_numbers, blocker_count: sub_issue_numbers.size } end |
#build_status(issue_number) ⇒ Object
56 57 58 |
# File 'lib/aidp/watch/state_store.rb', line 56 def build_status(issue_number) builds[issue_number.to_s] || {} end |
#change_request_data(pr_number) ⇒ Object
153 154 155 |
# File 'lib/aidp/watch/state_store.rb', line 153 def change_request_data(pr_number) change_requests[pr_number.to_s] end |
#change_request_processed?(pr_number) ⇒ Boolean
Change request tracking methods
149 150 151 |
# File 'lib/aidp/watch/state_store.rb', line 149 def change_request_processed?(pr_number) change_requests.key?(pr_number.to_s) end |
#ci_fix_completed?(pr_number) ⇒ Boolean
CI fix tracking methods
126 127 128 129 |
# File 'lib/aidp/watch/state_store.rb', line 126 def ci_fix_completed?(pr_number) fix_data = ci_fixes[pr_number.to_s] fix_data && fix_data["status"] == "completed" end |
#ci_fix_data(pr_number) ⇒ Object
131 132 133 |
# File 'lib/aidp/watch/state_store.rb', line 131 def ci_fix_data(pr_number) ci_fixes[pr_number.to_s] end |
#complete_auto_pr(pr_number, data = {}) ⇒ Object
Mark an auto PR as completed (ready for human review)
322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/aidp/watch/state_store.rb', line 322 def complete_auto_pr(pr_number, data = {}) key = pr_number.to_s existing = auto_prs[key] || {} auto_prs[key] = existing.merge({ "status" => "completed", "completed_at" => Time.now.utc.iso8601 }).merge(stringify_keys(data)) save! end |
#detection_comment_posted?(detection_key) ⇒ Boolean
Detection comment tracking methods (issue #280)
180 181 182 |
# File 'lib/aidp/watch/state_store.rb', line 180 def detection_comment_posted?(detection_key) detection_comments.key?(detection_key.to_s) end |
#find_build_by_pr(pr_number) ⇒ Hash?
Find the build/workstream metadata associated with a PR URL This is used to map change-request PRs back to their originating issues/worktrees.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/aidp/watch/state_store.rb', line 86 def find_build_by_pr(pr_number) builds.each do |issue_number, data| pr_url = data["pr_url"] next unless pr_url if pr_url.match?(%r{/pull/#{pr_number}\b}) return { issue_number: issue_number.to_i, branch: data["branch"], workstream: data["workstream"], pr_url: pr_url, status: data["status"] } end end nil end |
#mark_reaction_processed(comment_id, reaction_id) ⇒ Object
Mark a reaction as processed
272 273 274 275 276 277 278 |
# File 'lib/aidp/watch/state_store.rb', line 272 def mark_reaction_processed(comment_id, reaction_id) key = comment_id.to_s processed_reactions[key] ||= {"reaction_ids" => [], "last_checked" => nil} processed_reactions[key]["reaction_ids"] << reaction_id unless processed_reactions[key]["reaction_ids"].include?(reaction_id) processed_reactions[key]["last_checked"] = Time.now.utc.iso8601 save! end |
#parent_issue(sub_issue_number) ⇒ Object
370 371 372 |
# File 'lib/aidp/watch/state_store.rb', line 370 def parent_issue(sub_issue_number) hierarchies[sub_issue_number.to_s]&.dig("parent") end |
#plan_data(issue_number) ⇒ Object
26 27 28 |
# File 'lib/aidp/watch/state_store.rb', line 26 def plan_data(issue_number) plans[issue_number.to_s] end |
#plan_iteration_count(issue_number) ⇒ Object
30 31 32 33 34 |
# File 'lib/aidp/watch/state_store.rb', line 30 def plan_iteration_count(issue_number) plan = plans[issue_number.to_s] return 0 unless plan plan["iteration"] || 1 end |
#plan_processed?(issue_number) ⇒ Boolean
22 23 24 |
# File 'lib/aidp/watch/state_store.rb', line 22 def plan_processed?(issue_number) plans.key?(issue_number.to_s) end |
#processed_reaction_ids(comment_id) ⇒ Array<Integer>
Get IDs of reactions already processed for a comment
263 264 265 266 267 |
# File 'lib/aidp/watch/state_store.rb', line 263 def processed_reaction_ids(comment_id) data = processed_reactions[comment_id.to_s] return [] unless data data["reaction_ids"] || [] end |
#project_item_id(issue_number) ⇒ Object
Project tracking methods
343 344 345 |
# File 'lib/aidp/watch/state_store.rb', line 343 def project_item_id(issue_number) projects[issue_number.to_s]&.dig("item_id") end |
#project_sync_data(issue_number) ⇒ Object
354 355 356 |
# File 'lib/aidp/watch/state_store.rb', line 354 def project_sync_data(issue_number) projects[issue_number.to_s] || {} end |
#record_auto_pr_iteration(pr_number, data = {}) ⇒ Integer
Record an auto PR iteration
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/aidp/watch/state_store.rb', line 303 def record_auto_pr_iteration(pr_number, data = {}) key = pr_number.to_s existing = auto_prs[key] || {} iteration = (existing["iteration"] || 0) + 1 auto_prs[key] = { "iteration" => iteration, "last_processed_at" => Time.now.utc.iso8601, "status" => data[:status] || "in_progress", "metadata" => stringify_keys(data[:metadata] || {}) }.merge(stringify_keys(data.except(:status, :metadata))) save! iteration end |
#record_build_status(issue_number, status:, details: {}) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/aidp/watch/state_store.rb', line 60 def record_build_status(issue_number, status:, details: {}) builds[issue_number.to_s] = { "status" => status, "updated_at" => Time.now.utc.iso8601 }.merge(stringify_keys(details)) save! end |
#record_change_request(pr_number, data) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/aidp/watch/state_store.rb', line 157 def record_change_request(pr_number, data) payload = { "status" => data[:status], "timestamp" => data[:timestamp] || Time.now.utc.iso8601, "changes_applied" => data[:changes_applied], "commits" => data[:commits], "reason" => data[:reason], "clarification_count" => data[:clarification_count], "verification_reasons" => data[:verification_reasons], "missing_items" => data[:missing_items], "additional_work" => data[:additional_work] }.compact change_requests[pr_number.to_s] = payload save! end |
#record_ci_fix(pr_number, data) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/aidp/watch/state_store.rb', line 135 def record_ci_fix(pr_number, data) payload = { "status" => data[:status], "timestamp" => data[:timestamp] || Time.now.utc.iso8601, "reason" => data[:reason], "root_causes" => data[:root_causes], "fixes_count" => data[:fixes_count] }.compact ci_fixes[pr_number.to_s] = payload save! end |
#record_detection_comment(detection_key, timestamp:) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/aidp/watch/state_store.rb', line 184 def record_detection_comment(detection_key, timestamp:) detection_comments[detection_key.to_s] = { "timestamp" => , "posted_at" => Time.now.utc.iso8601 } save! end |
#record_plan(issue_number, data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/aidp/watch/state_store.rb', line 36 def record_plan(issue_number, data) existing_plan = plans[issue_number.to_s] iteration = existing_plan ? (existing_plan["iteration"] || 1) + 1 : 1 payload = { "summary" => data[:summary], "tasks" => data[:tasks], "questions" => data[:questions], "comment_body" => data[:comment_body], "comment_hint" => data[:comment_hint], "comment_id" => data[:comment_id], "posted_at" => data[:posted_at] || Time.now.utc.iso8601, "iteration" => iteration, "previous_iteration_at" => existing_plan ? existing_plan["posted_at"] : nil }.compact plans[issue_number.to_s] = payload save! end |
#record_project_item_id(issue_number, item_id) ⇒ Object
347 348 349 350 351 352 |
# File 'lib/aidp/watch/state_store.rb', line 347 def record_project_item_id(issue_number, item_id) projects[issue_number.to_s] ||= {} projects[issue_number.to_s]["item_id"] = item_id projects[issue_number.to_s]["synced_at"] = Time.now.utc.iso8601 save! end |
#record_project_sync(issue_number, data) ⇒ Object
358 359 360 361 362 363 |
# File 'lib/aidp/watch/state_store.rb', line 358 def record_project_sync(issue_number, data) projects[issue_number.to_s] ||= {} projects[issue_number.to_s].merge!(stringify_keys(data)) projects[issue_number.to_s]["synced_at"] = Time.now.utc.iso8601 save! end |
#record_review(pr_number, data) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/aidp/watch/state_store.rb', line 114 def record_review(pr_number, data) payload = { "timestamp" => data[:timestamp] || Time.now.utc.iso8601, "reviewers" => data[:reviewers], "total_findings" => data[:total_findings] }.compact reviews[pr_number.to_s] = payload save! end |
#record_sub_issues(parent_number, sub_issue_numbers) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/aidp/watch/state_store.rb', line 374 def record_sub_issues(parent_number, sub_issue_numbers) hierarchies[parent_number.to_s] ||= {} hierarchies[parent_number.to_s]["sub_issues"] = Array(sub_issue_numbers) hierarchies[parent_number.to_s]["created_at"] = Time.now.utc.iso8601 # Also record reverse mapping sub_issue_numbers.each do |sub_number| hierarchies[sub_number.to_s] ||= {} hierarchies[sub_number.to_s]["parent"] = parent_number end save! end |
#reset_change_request_state(pr_number) ⇒ Object
174 175 176 177 |
# File 'lib/aidp/watch/state_store.rb', line 174 def reset_change_request_state(pr_number) change_requests.delete(pr_number.to_s) save! end |
#review_data(pr_number) ⇒ Object
110 111 112 |
# File 'lib/aidp/watch/state_store.rb', line 110 def review_data(pr_number) reviews[pr_number.to_s] end |
#review_processed?(pr_number) ⇒ Boolean
Review tracking methods
106 107 108 |
# File 'lib/aidp/watch/state_store.rb', line 106 def review_processed?(pr_number) reviews.key?(pr_number.to_s) end |
#sub_issues(parent_number) ⇒ Object
Sub-issue tracking methods
366 367 368 |
# File 'lib/aidp/watch/state_store.rb', line 366 def sub_issues(parent_number) hierarchies[parent_number.to_s]&.dig("sub_issues") || [] end |
#track_comment_for_feedback(comment_id:, processor_type:, number:) ⇒ Object
Track a comment for feedback collection
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/aidp/watch/state_store.rb', line 249 def track_comment_for_feedback(comment_id:, processor_type:, number:) key = "#{processor_type}_#{number}" feedback_comments[key] = { "comment_id" => comment_id.to_s, "processor_type" => processor_type, "number" => number, "posted_at" => Time.now.utc.iso8601 } save! end |
#tracked_comments ⇒ Array<Hash>
Get all tracked comments with their metadata for feedback collection
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/aidp/watch/state_store.rb', line 196 def tracked_comments comments = [] # Collect from plans plans.each do |issue_number, data| next unless data["comment_id"] comments << { comment_id: data["comment_id"], processor_type: "plan", number: issue_number.to_i, posted_at: data["posted_at"] } end # Collect from reviews (if they store comment_id) reviews.each do |pr_number, data| next unless data["comment_id"] comments << { comment_id: data["comment_id"], processor_type: "review", number: pr_number.to_i, posted_at: data["timestamp"] } end # Collect from builds (if they store comment_id) builds.each do |issue_number, data| next unless data["comment_id"] comments << { comment_id: data["comment_id"], processor_type: "build", number: issue_number.to_i, posted_at: data["updated_at"] } end # Collect from feedback_comments (explicitly tracked) feedback_comments.each do |key, data| comments << { comment_id: data["comment_id"], processor_type: data["processor_type"], number: data["number"].to_i, posted_at: data["posted_at"] } end comments end |
#workstream_for_issue(issue_number) ⇒ Hash?
Retrieve workstream metadata for a given issue
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/aidp/watch/state_store.rb', line 70 def workstream_for_issue(issue_number) data = build_status(issue_number) return nil if data.nil? || data.empty? { issue_number: issue_number.to_i, branch: data["branch"], workstream: data["workstream"], pr_url: data["pr_url"], status: data["status"] } end |