Class: Aidp::Database::Repositories::ExperienceRunRepository
- Inherits:
-
Aidp::Database::Repository
- Object
- Aidp::Database::Repository
- Aidp::Database::Repositories::ExperienceRunRepository
- Defined in:
- lib/aidp/database/repositories/experience_run_repository.rb
Instance Attribute Summary
Attributes inherited from Aidp::Database::Repository
Instance Method Summary collapse
- #bundle_for_replay(run_id) ⇒ Object
- #children(parent_run_id) ⇒ Object
- #complete(run_id:, status:, output_payload:, metadata: {}) ⇒ Object
-
#initialize(project_dir: Dir.pwd) ⇒ ExperienceRunRepository
constructor
A new instance of ExperienceRunRepository.
- #load(run_id) ⇒ Object
- #start(task_id:, strategy_id:, workflow_id:, depth:, input_payload:, parent_run_id: nil, branch_key: nil, metadata: {}) ⇒ Object
Constructor Details
#initialize(project_dir: Dir.pwd) ⇒ ExperienceRunRepository
Returns a new instance of ExperienceRunRepository.
10 11 12 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 10 def initialize(project_dir: Dir.pwd) super(project_dir: project_dir, table_name: "experience_runs") end |
Instance Method Details
#bundle_for_replay(run_id) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 80 def bundle_for_replay(run_id) row = query_one( <<~SQL, SELECT runs.*, tasks.title AS task_title, tasks.description AS task_description, tasks.input_payload AS task_input_payload, tasks.context AS task_context, tasks.source_run_id AS task_source_run_id FROM experience_runs runs JOIN experience_tasks tasks ON tasks.id = runs.task_id WHERE runs.id = ? AND runs.project_dir = ? SQL [run_id, project_dir] ) return nil unless row run = deserialize_run(row) run.merge( task: { id: row["task_id"], title: row["task_title"], description: row["task_description"], input_payload: deserialize_json(row["task_input_payload"]) || {}, context: deserialize_json(row["task_context"]) || {}, source_run_id: row["task_source_run_id"] } ) end |
#children(parent_run_id) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 107 def children(parent_run_id) rows = query( "SELECT * FROM experience_runs WHERE parent_run_id = ? AND project_dir = ? ORDER BY started_at ASC", [parent_run_id, project_dir] ) rows.map { |row| deserialize_run(row) } end |
#complete(run_id:, status:, output_payload:, metadata: {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 47 def complete(run_id:, status:, output_payload:, metadata: {}) = (run_id).merge( || {}) execute( <<~SQL, UPDATE experience_runs SET status = ?, output_payload = ?, metadata = ?, completed_at = ? WHERE id = ? AND project_dir = ? SQL [ status, serialize_json(output_payload || {}), serialize_json(), , run_id, project_dir ] ) Aidp.log_debug("experience_run_repository", "completed", id: run_id, status: status) load(run_id) end |
#load(run_id) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 72 def load(run_id) row = query_one( "SELECT * FROM experience_runs WHERE id = ? AND project_dir = ?", [run_id, project_dir] ) deserialize_run(row) end |
#start(task_id:, strategy_id:, workflow_id:, depth:, input_payload:, parent_run_id: nil, branch_key: nil, metadata: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aidp/database/repositories/experience_run_repository.rb', line 14 def start(task_id:, strategy_id:, workflow_id:, depth:, input_payload:, parent_run_id: nil, branch_key: nil, metadata: {}) run_id = SecureRandom.uuid execute( insert_sql([ :id, :project_dir, :task_id, :strategy_id, :workflow_id, :parent_run_id, :branch_key, :status, :depth, :input_payload, :metadata ]), [ run_id, project_dir, task_id, strategy_id, workflow_id, parent_run_id, branch_key, "running", depth, serialize_json(input_payload || {}), serialize_json( || {}) ] ) Aidp.log_debug("experience_run_repository", "started", id: run_id, task_id: task_id, strategy_id: strategy_id, branch_key: branch_key, depth: depth) load(run_id) end |