Class: Aidp::StrategyExecution::ExperienceStore

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/strategy_execution/experience_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_dir: Dir.pwd) ⇒ ExperienceStore

Returns a new instance of ExperienceStore.



14
15
16
17
# File 'lib/aidp/strategy_execution/experience_store.rb', line 14

def initialize(project_dir: Dir.pwd)
  @project_dir = project_dir
  Aidp::Database.migrate_once!(@project_dir)
end

Instance Method Details

#complete_run(run_id:, status:, output_payload:, metadata: {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/aidp/strategy_execution/experience_store.rb', line 62

def complete_run(run_id:, status:, output_payload:, metadata: {})
  run = run_repository.complete(
    run_id: run_id,
    status: status,
    output_payload: output_payload,
    metadata: 
  )
  Aidp.log_debug("experience_store", "run_completed",
    run_id: run_id, status: status)
  run
end

#create_task(description:, title: nil, input_payload: {}, context: {}, source_run_id: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aidp/strategy_execution/experience_store.rb', line 29

def create_task(description:, title: nil, input_payload: {}, context: {}, source_run_id: nil)
  task = task_repository.create(
    description: description,
    title: title,
    input_payload: input_payload,
    context: context,
    source_run_id: source_run_id
  )
  Aidp.log_debug("experience_store", "task_created",
    task_id: task[:id], source_run_id: source_run_id)
  task
end

#record_artifact(run_id:, role:, path:, metadata: {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/aidp/strategy_execution/experience_store.rb', line 90

def record_artifact(run_id:, role:, path:, metadata: {})
  artifact_repository.record(
    run_id: run_id,
    role: role,
    path: path,
    metadata: 
  )
  Aidp.log_debug("experience_store", "artifact_recorded",
    run_id: run_id, role: role, path: path)
end

#record_evaluation(run_id:, evaluator_name:, score:, passed:, summary: nil, metadata: {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/aidp/strategy_execution/experience_store.rb', line 74

def record_evaluation(run_id:, evaluator_name:, score:, passed:, summary: nil, metadata: {})
  evaluation_repository.record(
    run_id: run_id,
    evaluator_name: evaluator_name,
    score: score,
    passed: passed,
    summary: summary,
    metadata: 
  )
  Aidp.log_debug("experience_store", "evaluation_recorded",
    run_id: run_id,
    evaluator_name: evaluator_name,
    score: score,
    passed: passed)
end

#register_strategy(strategy_spec) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/aidp/strategy_execution/experience_store.rb', line 19

def register_strategy(strategy_spec)
  record = strategy_repository.register(
    name: strategy_spec.name,
    spec: JSON.generate(strategy_spec.to_h)
  )
  Aidp.log_debug("experience_store", "strategy_registered",
    strategy_id: record[:id], name: strategy_spec.name)
  record
end

#replay_bundle(run_id) ⇒ Object



101
102
103
104
105
106
# File 'lib/aidp/strategy_execution/experience_store.rb', line 101

def replay_bundle(run_id)
  bundle = run_repository.bundle_for_replay(run_id)
  Aidp.log_debug("experience_store", "replay_bundle_loaded",
    run_id: run_id, found: !bundle.nil?)
  bundle
end

#run_details(run_id) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/aidp/strategy_execution/experience_store.rb', line 115

def run_details(run_id)
  run = run_repository.load(run_id)
  return nil unless run

  details = run.merge(
    evaluations: evaluation_repository.list_for_run(run_id),
    artifacts: artifact_repository.list_for_run(run_id),
    children: run_repository.children(run_id)
  )
  Aidp.log_debug("experience_store", "run_details_loaded",
    run_id: run_id,
    evaluation_count: details[:evaluations].length,
    artifact_count: details[:artifacts].length,
    child_count: details[:children].length)
  details
end

#start_run(task_id:, strategy_id:, workflow_id:, depth:, input_payload:, parent_run_id: nil, branch_key: nil, metadata: {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aidp/strategy_execution/experience_store.rb', line 42

def start_run(task_id:, strategy_id:, workflow_id:, depth:, input_payload:, parent_run_id: nil, branch_key: nil, metadata: {})
  run = run_repository.start(
    task_id: task_id,
    strategy_id: strategy_id,
    workflow_id: workflow_id,
    depth: depth,
    input_payload: input_payload,
    parent_run_id: parent_run_id,
    branch_key: branch_key,
    metadata: 
  )
  Aidp.log_debug("experience_store", "run_started",
    run_id: run[:id],
    task_id: task_id,
    strategy_id: strategy_id,
    branch_key: branch_key,
    depth: depth)
  run
end

#task_details(task_id) ⇒ Object



108
109
110
111
112
113
# File 'lib/aidp/strategy_execution/experience_store.rb', line 108

def task_details(task_id)
  task = task_repository.load(task_id)
  Aidp.log_debug("experience_store", "task_details_loaded",
    task_id: task_id, found: !task.nil?)
  task
end