aidp 0.47.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/aidp/cli/temporal_command.rb +132 -3
- data/lib/aidp/database/repositories/experience_artifact_repository.rb +40 -0
- data/lib/aidp/database/repositories/experience_evaluation_repository.rb +55 -0
- data/lib/aidp/database/repositories/experience_run_repository.rb +143 -0
- data/lib/aidp/database/repositories/experience_task_repository.rb +62 -0
- data/lib/aidp/database/repositories/strategy_repository.rb +59 -0
- data/lib/aidp/database/schema.rb +95 -1
- data/lib/aidp/database.rb +38 -0
- data/lib/aidp/strategy_execution/cli_protocol.rb +119 -0
- data/lib/aidp/strategy_execution/experience_store.rb +155 -0
- data/lib/aidp/strategy_execution/strategy_loader.rb +26 -0
- data/lib/aidp/strategy_execution/strategy_spec.rb +127 -0
- data/lib/aidp/temporal/activities/execute_cli_command_activity.rb +51 -0
- data/lib/aidp/temporal/activities/manage_experience_store_activity.rb +56 -0
- data/lib/aidp/temporal/workflows/strategy_branch_workflow.rb +294 -0
- data/lib/aidp/temporal/workflows/strategy_execution_workflow.rb +294 -0
- data/lib/aidp/temporal.rb +8 -0
- data/lib/aidp/version.rb +1 -1
- metadata +14 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "temporalio/workflow"
|
|
4
|
+
require_relative "base_workflow"
|
|
5
|
+
require_relative "../../strategy_execution/strategy_spec"
|
|
6
|
+
require_relative "../../strategy_execution/cli_protocol"
|
|
7
|
+
|
|
8
|
+
module Aidp
|
|
9
|
+
module Temporal
|
|
10
|
+
module Workflows
|
|
11
|
+
class StrategyBranchWorkflow < BaseWorkflow
|
|
12
|
+
# Must exceed the 30s heartbeat interval in ExecuteCliCommandActivity
|
|
13
|
+
# while staying below the agent/evaluator start_to_close budgets, so a
|
|
14
|
+
# missed beat does not time out a long-running CLI invocation.
|
|
15
|
+
HEARTBEAT_TIMEOUT = 120
|
|
16
|
+
|
|
17
|
+
def execute(input)
|
|
18
|
+
initialize_state(input)
|
|
19
|
+
log_workflow("execute_started",
|
|
20
|
+
branch_key: @branch&.dig(:key),
|
|
21
|
+
strategy_id: @strategy_id,
|
|
22
|
+
depth: @depth)
|
|
23
|
+
|
|
24
|
+
@run = start_run
|
|
25
|
+
log_workflow("run_started",
|
|
26
|
+
run_id: @run[:id],
|
|
27
|
+
branch_key: @branch&.dig(:key))
|
|
28
|
+
|
|
29
|
+
agent_result = execute_agent
|
|
30
|
+
fail_branch!(agent_result) unless agent_result[:success]
|
|
31
|
+
log_workflow("agent_completed",
|
|
32
|
+
run_id: @run[:id],
|
|
33
|
+
branch_key: @branch&.dig(:key),
|
|
34
|
+
artifact_count: Array(agent_result[:artifacts]).length)
|
|
35
|
+
|
|
36
|
+
evaluations = execute_evaluators(agent_result)
|
|
37
|
+
log_workflow("evaluator_completed",
|
|
38
|
+
run_id: @run[:id],
|
|
39
|
+
branch_key: @branch&.dig(:key),
|
|
40
|
+
evaluator_count: evaluations.length,
|
|
41
|
+
aggregate_score: aggregate_score(
|
|
42
|
+
evaluations.filter_map { |evaluation| evaluation[:score]&.to_f },
|
|
43
|
+
evaluations
|
|
44
|
+
))
|
|
45
|
+
|
|
46
|
+
artifacts = record_artifacts(agent_result, evaluations)
|
|
47
|
+
log_workflow("artifacts_recorded",
|
|
48
|
+
run_id: @run[:id],
|
|
49
|
+
branch_key: @branch&.dig(:key),
|
|
50
|
+
artifact_count: artifacts.length)
|
|
51
|
+
|
|
52
|
+
output = build_output(agent_result, evaluations, artifacts)
|
|
53
|
+
complete_run("completed", output)
|
|
54
|
+
|
|
55
|
+
log_workflow("run_completed",
|
|
56
|
+
run_id: @run[:id],
|
|
57
|
+
branch_key: @branch&.dig(:key),
|
|
58
|
+
status: "completed",
|
|
59
|
+
aggregate_score: output[:aggregate_score])
|
|
60
|
+
|
|
61
|
+
output
|
|
62
|
+
rescue Temporalio::Error::CanceledError
|
|
63
|
+
raise
|
|
64
|
+
rescue Aidp::StrategyExecution::CliProtocol::ProtocolError,
|
|
65
|
+
Aidp::Database::Error => e
|
|
66
|
+
Aidp.log_error("strategy_branch_workflow", "execute_failed",
|
|
67
|
+
run_id: @run&.dig(:id),
|
|
68
|
+
branch_key: @branch&.dig(:key),
|
|
69
|
+
error: e.message,
|
|
70
|
+
error_class: e.class.name)
|
|
71
|
+
complete_run("failed", {error: e.message}) if @run && !run_completed?
|
|
72
|
+
raise
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def initialize_state(input)
|
|
78
|
+
@project_dir = input[:project_dir]
|
|
79
|
+
@task = input[:task]
|
|
80
|
+
@task_id = input[:task_id]
|
|
81
|
+
@strategy = Aidp::StrategyExecution::StrategySpec.from_hash(input[:strategy])
|
|
82
|
+
@strategy_id = input[:strategy_id]
|
|
83
|
+
@branch = input[:branch]
|
|
84
|
+
@depth = input[:depth] || 0
|
|
85
|
+
@parent_run_id = input[:parent_run_id]
|
|
86
|
+
@run_completed = false
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def start_run
|
|
90
|
+
execute_activity(
|
|
91
|
+
"start_run",
|
|
92
|
+
task_id: @task_id,
|
|
93
|
+
strategy_id: @strategy_id,
|
|
94
|
+
workflow_id: workflow_info.workflow_id,
|
|
95
|
+
depth: @depth,
|
|
96
|
+
input_payload: {task: @task, branch: @branch},
|
|
97
|
+
parent_run_id: @parent_run_id,
|
|
98
|
+
branch_key: @branch[:key],
|
|
99
|
+
metadata: {workflow_type: self.class.name}
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def execute_agent
|
|
104
|
+
log_workflow("agent_started",
|
|
105
|
+
run_id: @run[:id],
|
|
106
|
+
branch_key: @branch&.dig(:key))
|
|
107
|
+
|
|
108
|
+
Temporalio::Workflow.execute_activity(
|
|
109
|
+
Activities::ExecuteCliCommandActivity,
|
|
110
|
+
{
|
|
111
|
+
project_dir: @project_dir,
|
|
112
|
+
command: @branch[:command],
|
|
113
|
+
role: "agent",
|
|
114
|
+
request: {
|
|
115
|
+
task: @task,
|
|
116
|
+
branch: @branch,
|
|
117
|
+
depth: @depth,
|
|
118
|
+
strategy: @strategy.to_h
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
**cli_activity_options(
|
|
122
|
+
start_to_close_timeout: activity_timeout(:agent, 900),
|
|
123
|
+
heartbeat_timeout: activity_heartbeat_timeout
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def fail_branch!(agent_result)
|
|
129
|
+
message = agent_result[:error] || agent_result[:summary] || "agent execution reported failure"
|
|
130
|
+
complete_run("failed", {error: message, agent_result: agent_result})
|
|
131
|
+
raise Aidp::StrategyExecution::CliProtocol::ProtocolError, message
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def execute_evaluators(agent_result)
|
|
135
|
+
@strategy.evaluator_definitions.map do |evaluator|
|
|
136
|
+
log_workflow("evaluator_started",
|
|
137
|
+
run_id: @run[:id],
|
|
138
|
+
branch_key: @branch&.dig(:key),
|
|
139
|
+
evaluator_name: evaluator[:name])
|
|
140
|
+
|
|
141
|
+
result = Temporalio::Workflow.execute_activity(
|
|
142
|
+
Activities::ExecuteCliCommandActivity,
|
|
143
|
+
{
|
|
144
|
+
project_dir: @project_dir,
|
|
145
|
+
command: evaluator[:command],
|
|
146
|
+
role: "evaluator",
|
|
147
|
+
request: {
|
|
148
|
+
task: @task,
|
|
149
|
+
candidate: agent_result,
|
|
150
|
+
evaluator: evaluator,
|
|
151
|
+
depth: @depth,
|
|
152
|
+
strategy: @strategy.to_h
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
**cli_activity_options(
|
|
156
|
+
start_to_close_timeout: activity_timeout(:evaluator, 300),
|
|
157
|
+
heartbeat_timeout: activity_heartbeat_timeout
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
execute_activity(
|
|
162
|
+
"record_evaluation",
|
|
163
|
+
run_id: @run[:id],
|
|
164
|
+
evaluator_name: evaluator[:name],
|
|
165
|
+
score: result[:score],
|
|
166
|
+
passed: result[:passed],
|
|
167
|
+
summary: result[:summary],
|
|
168
|
+
metadata: result[:metadata] || {}
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
result.merge(name: evaluator[:name])
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def record_artifacts(agent_result, evaluations)
|
|
176
|
+
records = []
|
|
177
|
+
|
|
178
|
+
Array(agent_result[:artifacts]).each do |path|
|
|
179
|
+
execute_activity(
|
|
180
|
+
"record_artifact",
|
|
181
|
+
run_id: @run[:id],
|
|
182
|
+
role: "agent",
|
|
183
|
+
path: path,
|
|
184
|
+
metadata: {branch: @branch[:key]}
|
|
185
|
+
)
|
|
186
|
+
records << {role: "agent", path: path}
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
evaluations.each do |evaluation|
|
|
190
|
+
Array(evaluation[:artifacts]).each do |path|
|
|
191
|
+
execute_activity(
|
|
192
|
+
"record_artifact",
|
|
193
|
+
run_id: @run[:id],
|
|
194
|
+
role: evaluation[:name],
|
|
195
|
+
path: path,
|
|
196
|
+
metadata: {branch: @branch[:key]}
|
|
197
|
+
)
|
|
198
|
+
records << {role: evaluation[:name], path: path}
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
records
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def build_output(agent_result, evaluations, artifacts)
|
|
206
|
+
scores = evaluations.filter_map { |evaluation| evaluation[:score]&.to_f }
|
|
207
|
+
|
|
208
|
+
{
|
|
209
|
+
status: "completed",
|
|
210
|
+
run_id: @run[:id],
|
|
211
|
+
branch_key: @branch[:key],
|
|
212
|
+
branch_name: @branch[:name],
|
|
213
|
+
output: agent_result[:output] || agent_result[:content],
|
|
214
|
+
summary: agent_result[:summary],
|
|
215
|
+
metadata: agent_result[:metadata] || {},
|
|
216
|
+
subtasks: agent_result[:subtasks] || [],
|
|
217
|
+
evaluations: evaluations,
|
|
218
|
+
artifacts: artifacts,
|
|
219
|
+
aggregate_score: aggregate_score(scores, evaluations)
|
|
220
|
+
}
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def aggregate_score(scores, evaluations)
|
|
224
|
+
normalized = if scores.empty?
|
|
225
|
+
pass_ratio(evaluations)
|
|
226
|
+
else
|
|
227
|
+
scores.sum / scores.length
|
|
228
|
+
end
|
|
229
|
+
bonus = evaluations.count { |evaluation| evaluation[:passed] } * 0.1
|
|
230
|
+
normalized + bonus
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def pass_ratio(evaluations)
|
|
234
|
+
return 0.0 if evaluations.empty?
|
|
235
|
+
|
|
236
|
+
evaluations.count { |evaluation| evaluation[:passed] }.to_f / evaluations.length
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def complete_run(status, output)
|
|
240
|
+
execute_activity(
|
|
241
|
+
"complete_run",
|
|
242
|
+
run_id: @run[:id],
|
|
243
|
+
status: status,
|
|
244
|
+
output_payload: output,
|
|
245
|
+
metadata: {branch_key: @branch[:key]}
|
|
246
|
+
)
|
|
247
|
+
@run_completed = true
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def run_completed?
|
|
251
|
+
@run_completed
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def execute_activity(operation, payload)
|
|
255
|
+
Temporalio::Workflow.execute_activity(
|
|
256
|
+
Activities::ManageExperienceStoreActivity,
|
|
257
|
+
{
|
|
258
|
+
project_dir: @project_dir,
|
|
259
|
+
operation: operation,
|
|
260
|
+
payload: payload
|
|
261
|
+
},
|
|
262
|
+
**store_activity_options(operation)
|
|
263
|
+
)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def activity_timeout(role, fallback)
|
|
267
|
+
value = @strategy.timeouts[role]
|
|
268
|
+
number = value.to_i
|
|
269
|
+
number.positive? ? number : fallback
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def cli_activity_options(overrides = {})
|
|
273
|
+
options = activity_options(overrides)
|
|
274
|
+
options.merge(retry_policy: options.fetch(:retry_policy, {}).merge(maximum_attempts: 1))
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def store_activity_options(operation)
|
|
278
|
+
options = activity_options(start_to_close_timeout: 60)
|
|
279
|
+
return options unless %w[start_run record_evaluation record_artifact].include?(operation)
|
|
280
|
+
|
|
281
|
+
options.merge(retry_policy: options.fetch(:retry_policy, {}).merge(maximum_attempts: 1))
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def activity_heartbeat_timeout
|
|
285
|
+
HEARTBEAT_TIMEOUT
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def activity_options(overrides = {})
|
|
289
|
+
self.class.activity_options(overrides)
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "temporalio/workflow"
|
|
4
|
+
require_relative "base_workflow"
|
|
5
|
+
require_relative "../../strategy_execution/strategy_spec"
|
|
6
|
+
require_relative "../../strategy_execution/cli_protocol"
|
|
7
|
+
|
|
8
|
+
module Aidp
|
|
9
|
+
module Temporal
|
|
10
|
+
module Workflows
|
|
11
|
+
class StrategyExecutionWorkflow < BaseWorkflow
|
|
12
|
+
workflow_query
|
|
13
|
+
def progress
|
|
14
|
+
{
|
|
15
|
+
state: @state,
|
|
16
|
+
depth: @depth,
|
|
17
|
+
strategy: @strategy&.name,
|
|
18
|
+
task: @task&.fetch(:description, nil),
|
|
19
|
+
run_id: @run&.fetch(:id, nil),
|
|
20
|
+
winning_branch: @winning_branch&.fetch(:branch_key, nil)
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def execute(input)
|
|
25
|
+
initialize_state(input)
|
|
26
|
+
log_workflow("execute_started",
|
|
27
|
+
strategy: @strategy.name,
|
|
28
|
+
depth: @depth,
|
|
29
|
+
task_id: @task[:id])
|
|
30
|
+
|
|
31
|
+
@strategy_record = register_strategy
|
|
32
|
+
log_workflow("strategy_registered", strategy_id: @strategy_record[:id])
|
|
33
|
+
|
|
34
|
+
@task_record = ensure_task
|
|
35
|
+
log_workflow("task_ensured", task_id: @task_record[:id])
|
|
36
|
+
|
|
37
|
+
@run = start_run
|
|
38
|
+
log_workflow("run_started", run_id: @run[:id])
|
|
39
|
+
|
|
40
|
+
transition_to(:fanout)
|
|
41
|
+
branches = launch_branches
|
|
42
|
+
log_workflow("branches_launched", count: branches.length)
|
|
43
|
+
|
|
44
|
+
@winning_branch = select_winning_branch(branches)
|
|
45
|
+
log_workflow("winning_branch_selected",
|
|
46
|
+
branch_key: @winning_branch&.fetch(:branch_key, nil),
|
|
47
|
+
aggregate_score: @winning_branch&.fetch(:aggregate_score, nil))
|
|
48
|
+
|
|
49
|
+
transition_to(:merge)
|
|
50
|
+
merged_children = execute_subtasks(@winning_branch)
|
|
51
|
+
log_workflow("subtasks_completed", count: merged_children.length)
|
|
52
|
+
|
|
53
|
+
result = build_result(branches, merged_children)
|
|
54
|
+
|
|
55
|
+
complete_run("completed", result)
|
|
56
|
+
log_workflow("execute_completed", run_id: @run[:id])
|
|
57
|
+
result
|
|
58
|
+
rescue Temporalio::Error::CanceledError
|
|
59
|
+
raise
|
|
60
|
+
rescue Aidp::StrategyExecution::CliProtocol::ProtocolError,
|
|
61
|
+
Aidp::Database::Error => e
|
|
62
|
+
Aidp.log_error("strategy_execution_workflow", "execute_failed",
|
|
63
|
+
run_id: @run&.fetch(:id, nil),
|
|
64
|
+
depth: @depth,
|
|
65
|
+
error: e.message,
|
|
66
|
+
error_class: e.class.name)
|
|
67
|
+
complete_run("failed", {error: e.message}) if @run
|
|
68
|
+
raise
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def initialize_state(input)
|
|
74
|
+
@project_dir = input[:project_dir]
|
|
75
|
+
@strategy = Aidp::StrategyExecution::StrategySpec.from_hash(input[:strategy])
|
|
76
|
+
@task = normalize_task(input[:task])
|
|
77
|
+
@depth = input[:depth] || 0
|
|
78
|
+
@parent_run_id = input[:parent_run_id]
|
|
79
|
+
@state = :init
|
|
80
|
+
@winning_branch = nil
|
|
81
|
+
@strategy_record = nil
|
|
82
|
+
@task_record = nil
|
|
83
|
+
@run = nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def register_strategy
|
|
87
|
+
execute_store(
|
|
88
|
+
"register_strategy",
|
|
89
|
+
strategy: @strategy.to_h
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def ensure_task
|
|
94
|
+
existing_task = existing_task_record
|
|
95
|
+
return existing_task if existing_task
|
|
96
|
+
|
|
97
|
+
execute_store(
|
|
98
|
+
"create_task",
|
|
99
|
+
title: @task[:title],
|
|
100
|
+
description: @task[:description],
|
|
101
|
+
input_payload: @task[:input_payload] || {},
|
|
102
|
+
context: @task[:context] || {},
|
|
103
|
+
source_run_id: @task[:source_run_id]
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def existing_task_record
|
|
108
|
+
task_id = @task[:id]
|
|
109
|
+
return nil unless task_id
|
|
110
|
+
|
|
111
|
+
execute_store("task_details", task_id: task_id)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def start_run
|
|
115
|
+
execute_store(
|
|
116
|
+
"start_run",
|
|
117
|
+
task_id: @task_record[:id],
|
|
118
|
+
strategy_id: @strategy_record[:id],
|
|
119
|
+
workflow_id: workflow_info.workflow_id,
|
|
120
|
+
depth: @depth,
|
|
121
|
+
input_payload: {task: @task, strategy: @strategy.to_h},
|
|
122
|
+
parent_run_id: @parent_run_id,
|
|
123
|
+
metadata: {workflow_type: self.class.name}
|
|
124
|
+
)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def launch_branches
|
|
128
|
+
@strategy.branch_commands.map.with_index do |branch, index|
|
|
129
|
+
log_workflow("branch_launching",
|
|
130
|
+
branch_key: branch[:key],
|
|
131
|
+
branch_index: index,
|
|
132
|
+
run_id: @run[:id])
|
|
133
|
+
|
|
134
|
+
Temporalio::Workflow.execute_child_workflow(
|
|
135
|
+
StrategyBranchWorkflow,
|
|
136
|
+
{
|
|
137
|
+
project_dir: @project_dir,
|
|
138
|
+
task: @task_record,
|
|
139
|
+
task_id: @task_record[:id],
|
|
140
|
+
strategy: @strategy.to_h,
|
|
141
|
+
strategy_id: @strategy_record[:id],
|
|
142
|
+
branch: branch,
|
|
143
|
+
depth: @depth,
|
|
144
|
+
parent_run_id: @run[:id]
|
|
145
|
+
},
|
|
146
|
+
id: "#{workflow_info.workflow_id}-branch-#{index}",
|
|
147
|
+
**child_workflow_options
|
|
148
|
+
)
|
|
149
|
+
end.map(&:result)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def select_winning_branch(branches)
|
|
153
|
+
winning = case @strategy.merge_policy
|
|
154
|
+
when "highest_score", "critic_vote_then_merge"
|
|
155
|
+
branches.max_by { |branch| branch[:aggregate_score].to_f }
|
|
156
|
+
else
|
|
157
|
+
branches.first
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
log_workflow("merge_policy_applied",
|
|
161
|
+
merge_policy: @strategy.merge_policy,
|
|
162
|
+
candidates: branches.length,
|
|
163
|
+
winning_branch_key: winning&.fetch(:branch_key, nil),
|
|
164
|
+
run_id: @run[:id],
|
|
165
|
+
depth: @depth)
|
|
166
|
+
|
|
167
|
+
winning
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def execute_subtasks(winning_branch)
|
|
171
|
+
subtasks = Array(winning_branch[:subtasks])
|
|
172
|
+
return [] if subtasks.empty?
|
|
173
|
+
return [] if @depth >= @strategy.max_depth
|
|
174
|
+
|
|
175
|
+
log_workflow("recursive_fanout_starting",
|
|
176
|
+
subtask_count: subtasks.length,
|
|
177
|
+
run_id: @run[:id],
|
|
178
|
+
depth: @depth)
|
|
179
|
+
|
|
180
|
+
transition_to(:recursive_fanout)
|
|
181
|
+
|
|
182
|
+
subtasks.map.with_index do |subtask, index|
|
|
183
|
+
Temporalio::Workflow.execute_child_workflow(
|
|
184
|
+
StrategyExecutionWorkflow,
|
|
185
|
+
{
|
|
186
|
+
project_dir: @project_dir,
|
|
187
|
+
strategy: @strategy.to_h,
|
|
188
|
+
task: normalize_subtask(subtask),
|
|
189
|
+
depth: @depth + 1,
|
|
190
|
+
parent_run_id: @run[:id]
|
|
191
|
+
},
|
|
192
|
+
id: "#{workflow_info.workflow_id}-subtask-#{index}",
|
|
193
|
+
**child_workflow_options
|
|
194
|
+
)
|
|
195
|
+
end.map(&:result)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def build_result(branches, merged_children)
|
|
199
|
+
{
|
|
200
|
+
status: "completed",
|
|
201
|
+
run_id: @run[:id],
|
|
202
|
+
task_id: @task_record[:id],
|
|
203
|
+
strategy: @strategy.name,
|
|
204
|
+
depth: @depth,
|
|
205
|
+
winning_branch: @winning_branch,
|
|
206
|
+
branch_count: branches.length,
|
|
207
|
+
branches: branches,
|
|
208
|
+
merged_children: merged_children
|
|
209
|
+
}
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def complete_run(status, output)
|
|
213
|
+
execute_store(
|
|
214
|
+
"complete_run",
|
|
215
|
+
run_id: @run[:id],
|
|
216
|
+
status: status,
|
|
217
|
+
output_payload: output,
|
|
218
|
+
metadata: {
|
|
219
|
+
state: @state,
|
|
220
|
+
winning_branch: @winning_branch&.fetch(:branch_key, nil)
|
|
221
|
+
}
|
|
222
|
+
)
|
|
223
|
+
log_workflow("run_completed",
|
|
224
|
+
run_id: @run[:id],
|
|
225
|
+
status: status,
|
|
226
|
+
depth: @depth,
|
|
227
|
+
branch_key: @winning_branch&.fetch(:branch_key, nil))
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def execute_store(operation, payload)
|
|
231
|
+
Temporalio::Workflow.execute_activity(
|
|
232
|
+
Activities::ManageExperienceStoreActivity,
|
|
233
|
+
{
|
|
234
|
+
project_dir: @project_dir,
|
|
235
|
+
operation: operation,
|
|
236
|
+
payload: payload
|
|
237
|
+
},
|
|
238
|
+
**store_activity_options(operation)
|
|
239
|
+
)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def child_workflow_options
|
|
243
|
+
{
|
|
244
|
+
task_queue: workflow_info.task_queue,
|
|
245
|
+
execution_timeout: 3600
|
|
246
|
+
}
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def store_activity_options(operation)
|
|
250
|
+
options = activity_options(start_to_close_timeout: 60)
|
|
251
|
+
return options unless %w[create_task start_run].include?(operation)
|
|
252
|
+
|
|
253
|
+
options.merge(retry_policy: options.fetch(:retry_policy, {}).merge(maximum_attempts: 1))
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def normalize_task(task)
|
|
257
|
+
normalized = (task || {}).transform_keys(&:to_sym)
|
|
258
|
+
description = normalized[:description].to_s
|
|
259
|
+
raise ArgumentError, "task description is required" if description.empty?
|
|
260
|
+
|
|
261
|
+
normalized
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def normalize_subtask(subtask)
|
|
265
|
+
data = case subtask
|
|
266
|
+
when Hash then subtask.transform_keys(&:to_sym)
|
|
267
|
+
else {description: subtask.to_s}
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
{
|
|
271
|
+
title: data[:title],
|
|
272
|
+
description: data[:description].to_s,
|
|
273
|
+
input_payload: data[:input_payload] || {},
|
|
274
|
+
context: data[:context] || {}
|
|
275
|
+
}
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def transition_to(state)
|
|
279
|
+
previous = @state
|
|
280
|
+
@state = state
|
|
281
|
+
log_workflow("state_transition",
|
|
282
|
+
from: previous,
|
|
283
|
+
to: state,
|
|
284
|
+
run_id: @run&.fetch(:id, nil),
|
|
285
|
+
depth: @depth)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def activity_options(overrides = {})
|
|
289
|
+
self.class.activity_options(overrides)
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
data/lib/aidp/temporal.rb
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
# - IssueToPrWorkflow: Full issue analysis → implementation → PR pipeline
|
|
14
14
|
# - WorkLoopWorkflow: Fix-forward iteration pattern
|
|
15
15
|
# - SubIssueWorkflow: Child workflow for decomposed tasks
|
|
16
|
+
# - StrategyExecutionWorkflow: Generic strategy-as-data execution
|
|
17
|
+
# - StrategyBranchWorkflow: Speculative branch execution for strategies
|
|
16
18
|
#
|
|
17
19
|
# Activities:
|
|
18
20
|
# - RunAgentActivity: Execute AI agent
|
|
@@ -24,6 +26,8 @@
|
|
|
24
26
|
# - PrepareNextIterationActivity: Set up next iteration
|
|
25
27
|
# - RecordCheckpointActivity: Save progress
|
|
26
28
|
# - CreatePrActivity: Create GitHub PR
|
|
29
|
+
# - ExecuteCliCommandActivity: Generic agent/evaluator CLI protocol runner
|
|
30
|
+
# - ManageExperienceStoreActivity: Persist strategy experience data
|
|
27
31
|
|
|
28
32
|
module Aidp
|
|
29
33
|
module Temporal
|
|
@@ -104,6 +108,8 @@ require_relative "temporal/workflows/base_workflow"
|
|
|
104
108
|
require_relative "temporal/workflows/issue_to_pr_workflow"
|
|
105
109
|
require_relative "temporal/workflows/work_loop_workflow"
|
|
106
110
|
require_relative "temporal/workflows/sub_issue_workflow"
|
|
111
|
+
require_relative "temporal/workflows/strategy_branch_workflow"
|
|
112
|
+
require_relative "temporal/workflows/strategy_execution_workflow"
|
|
107
113
|
|
|
108
114
|
# Require activities
|
|
109
115
|
require_relative "temporal/activities/base_activity"
|
|
@@ -118,3 +124,5 @@ require_relative "temporal/activities/record_checkpoint_activity"
|
|
|
118
124
|
require_relative "temporal/activities/create_pr_activity"
|
|
119
125
|
require_relative "temporal/activities/run_work_loop_iteration_activity"
|
|
120
126
|
require_relative "temporal/activities/analyze_sub_task_activity"
|
|
127
|
+
require_relative "temporal/activities/execute_cli_command_activity"
|
|
128
|
+
require_relative "temporal/activities/manage_experience_store_activity"
|
data/lib/aidp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aidp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.48.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bart Agapinan
|
|
@@ -374,6 +374,10 @@ files:
|
|
|
374
374
|
- lib/aidp/database/repositories/checkpoint_repository.rb
|
|
375
375
|
- lib/aidp/database/repositories/deprecated_models_repository.rb
|
|
376
376
|
- lib/aidp/database/repositories/evaluation_repository.rb
|
|
377
|
+
- lib/aidp/database/repositories/experience_artifact_repository.rb
|
|
378
|
+
- lib/aidp/database/repositories/experience_evaluation_repository.rb
|
|
379
|
+
- lib/aidp/database/repositories/experience_run_repository.rb
|
|
380
|
+
- lib/aidp/database/repositories/experience_task_repository.rb
|
|
377
381
|
- lib/aidp/database/repositories/harness_state_repository.rb
|
|
378
382
|
- lib/aidp/database/repositories/job_repository.rb
|
|
379
383
|
- lib/aidp/database/repositories/model_cache_repository.rb
|
|
@@ -383,6 +387,7 @@ files:
|
|
|
383
387
|
- lib/aidp/database/repositories/provider_info_cache_repository.rb
|
|
384
388
|
- lib/aidp/database/repositories/provider_metrics_repository.rb
|
|
385
389
|
- lib/aidp/database/repositories/secrets_repository.rb
|
|
390
|
+
- lib/aidp/database/repositories/strategy_repository.rb
|
|
386
391
|
- lib/aidp/database/repositories/task_repository.rb
|
|
387
392
|
- lib/aidp/database/repositories/template_version_repository.rb
|
|
388
393
|
- lib/aidp/database/repositories/watch_state_repository.rb
|
|
@@ -574,6 +579,10 @@ files:
|
|
|
574
579
|
- lib/aidp/storage/csv_storage.rb
|
|
575
580
|
- lib/aidp/storage/file_manager.rb
|
|
576
581
|
- lib/aidp/storage/json_storage.rb
|
|
582
|
+
- lib/aidp/strategy_execution/cli_protocol.rb
|
|
583
|
+
- lib/aidp/strategy_execution/experience_store.rb
|
|
584
|
+
- lib/aidp/strategy_execution/strategy_loader.rb
|
|
585
|
+
- lib/aidp/strategy_execution/strategy_spec.rb
|
|
577
586
|
- lib/aidp/style_guide/selector.rb
|
|
578
587
|
- lib/aidp/temporal.rb
|
|
579
588
|
- lib/aidp/temporal/activities/analyze_issue_activity.rb
|
|
@@ -583,6 +592,8 @@ files:
|
|
|
583
592
|
- lib/aidp/temporal/activities/create_pr_activity.rb
|
|
584
593
|
- lib/aidp/temporal/activities/create_prompt_activity.rb
|
|
585
594
|
- lib/aidp/temporal/activities/diagnose_failure_activity.rb
|
|
595
|
+
- lib/aidp/temporal/activities/execute_cli_command_activity.rb
|
|
596
|
+
- lib/aidp/temporal/activities/manage_experience_store_activity.rb
|
|
586
597
|
- lib/aidp/temporal/activities/prepare_next_iteration_activity.rb
|
|
587
598
|
- lib/aidp/temporal/activities/record_checkpoint_activity.rb
|
|
588
599
|
- lib/aidp/temporal/activities/run_agent_activity.rb
|
|
@@ -594,6 +605,8 @@ files:
|
|
|
594
605
|
- lib/aidp/temporal/workflow_client.rb
|
|
595
606
|
- lib/aidp/temporal/workflows/base_workflow.rb
|
|
596
607
|
- lib/aidp/temporal/workflows/issue_to_pr_workflow.rb
|
|
608
|
+
- lib/aidp/temporal/workflows/strategy_branch_workflow.rb
|
|
609
|
+
- lib/aidp/temporal/workflows/strategy_execution_workflow.rb
|
|
597
610
|
- lib/aidp/temporal/workflows/sub_issue_workflow.rb
|
|
598
611
|
- lib/aidp/temporal/workflows/work_loop_workflow.rb
|
|
599
612
|
- lib/aidp/tooling_detector.rb
|