active_harness 0.2.16 → 0.2.17
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/active_harness/pipeline.rb +41 -20
- data/lib/active_harness/tribunal/hooks.rb +8 -0
- data/lib/active_harness/tribunal.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e67acd826c0203c211c8a94266120d46981b587936b4ea6a29695b608ad76fa5
|
|
4
|
+
data.tar.gz: f21dded079561c202df392deb3199aa99df499a26fcd690c2bfc559290c17c09
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a248a63543848edc58386f8b5a025f247c624dc5b02696ca1c23eb56ecf3d2505edf838fc7c4400fd141013eccd5b35d4a70d812520556445f368cdcb7a3c9b2
|
|
7
|
+
data.tar.gz: 9dd1c65dba72bc37d87b1afc81835a169e1de43eddffbc33900a2e88fdc8eb561ddbab5b6d7e68129389cd10818927a011d9c7d4f9405ab161ae80d8b74d5649
|
|
@@ -129,17 +129,23 @@ module ActiveHarness
|
|
|
129
129
|
@payload = value
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
-
def initialize(input:, context: {}, memory: nil
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
@
|
|
136
|
-
@
|
|
137
|
-
@
|
|
138
|
-
@
|
|
139
|
-
@
|
|
140
|
-
@
|
|
141
|
-
@
|
|
142
|
-
@
|
|
132
|
+
def initialize(input:, context: {}, memory: nil,
|
|
133
|
+
stream: nil, agent_event_stream: nil,
|
|
134
|
+
tribunal_event_stream: nil, pipeline_event_stream: nil)
|
|
135
|
+
@original_input = input
|
|
136
|
+
@payload = input
|
|
137
|
+
@context = context.dup
|
|
138
|
+
@memory = memory
|
|
139
|
+
@stream = stream
|
|
140
|
+
@agent_event_stream = agent_event_stream
|
|
141
|
+
@tribunal_event_stream = tribunal_event_stream
|
|
142
|
+
@pipeline_event_stream = pipeline_event_stream
|
|
143
|
+
@step_results = {}
|
|
144
|
+
@stopped = false
|
|
145
|
+
@stopped_at = nil
|
|
146
|
+
@stop_reason = nil
|
|
147
|
+
@execution_time = nil
|
|
148
|
+
@output = nil
|
|
143
149
|
end
|
|
144
150
|
|
|
145
151
|
def stopped?
|
|
@@ -170,7 +176,8 @@ module ActiveHarness
|
|
|
170
176
|
@stopped = true
|
|
171
177
|
@stopped_at = step.name
|
|
172
178
|
@stop_reason = result
|
|
173
|
-
config[:hooks][:stopped]
|
|
179
|
+
blk = config[:hooks][:stopped]
|
|
180
|
+
instance_exec(step.name, result, &blk) if blk
|
|
174
181
|
break
|
|
175
182
|
end
|
|
176
183
|
end
|
|
@@ -186,7 +193,8 @@ module ActiveHarness
|
|
|
186
193
|
)
|
|
187
194
|
|
|
188
195
|
last_result = @step_results[@step_results.keys.last]
|
|
189
|
-
config[:hooks][:complete]
|
|
196
|
+
blk = config[:hooks][:complete]
|
|
197
|
+
instance_exec(last_result, &blk) if blk
|
|
190
198
|
end
|
|
191
199
|
|
|
192
200
|
self
|
|
@@ -195,23 +203,36 @@ module ActiveHarness
|
|
|
195
203
|
private
|
|
196
204
|
|
|
197
205
|
def execute_step(step)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
if step.tribunal?
|
|
207
|
+
agent = step.agent_class.new(
|
|
208
|
+
input: @payload,
|
|
209
|
+
context: @context.dup,
|
|
210
|
+
stream: @stream,
|
|
211
|
+
agent_event_stream: @agent_event_stream,
|
|
212
|
+
tribunal_event_stream: @tribunal_event_stream
|
|
213
|
+
)
|
|
203
214
|
agent.call
|
|
215
|
+
else
|
|
216
|
+
agent = step.agent_class.new(
|
|
217
|
+
input: @payload,
|
|
218
|
+
context: @context.dup,
|
|
219
|
+
stream: @stream,
|
|
220
|
+
event_stream: @agent_event_stream
|
|
221
|
+
)
|
|
222
|
+
agent.call.result
|
|
204
223
|
end
|
|
205
224
|
end
|
|
206
225
|
|
|
207
226
|
# Global hook: receives (step_name, data)
|
|
208
227
|
def fire_global(event, step_name, data, config)
|
|
209
|
-
config[:hooks][event]
|
|
228
|
+
blk = config[:hooks][event]
|
|
229
|
+
instance_exec(step_name, data, &blk) if blk
|
|
210
230
|
end
|
|
211
231
|
|
|
212
232
|
# Per-step hook: receives (data) only
|
|
213
233
|
def fire_step(event, step_name, data, config)
|
|
214
|
-
config[:step_hooks][step_name]&.dig(event)
|
|
234
|
+
blk = config[:step_hooks][step_name]&.dig(event)
|
|
235
|
+
instance_exec(data, &blk) if blk
|
|
215
236
|
end
|
|
216
237
|
end
|
|
217
238
|
end
|
|
@@ -76,6 +76,14 @@ module ActiveHarness
|
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
# Fire the DSL-registered hook AND the external tribunal_event_stream lambda (if set).
|
|
80
|
+
def fire(event, *args)
|
|
81
|
+
run_hook(event, *args)
|
|
82
|
+
@tribunal_event_stream&.call(event, *args)
|
|
83
|
+
rescue IOError, ActionController::Live::ClientDisconnected
|
|
84
|
+
nil
|
|
85
|
+
end
|
|
86
|
+
|
|
79
87
|
# Like run_hook but uses the return value to replace the passed value.
|
|
80
88
|
# Used by :before_verdict to allow results transformation before verdict computation.
|
|
81
89
|
def transform_hook(event, value)
|
|
@@ -82,12 +82,12 @@ module ActiveHarness
|
|
|
82
82
|
# - If ALL agents fail/timeout, raises Errors::AllAgentsFailed.
|
|
83
83
|
def call
|
|
84
84
|
agents = resolve_agents
|
|
85
|
-
|
|
85
|
+
fire(:before_call)
|
|
86
86
|
|
|
87
87
|
started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
88
88
|
|
|
89
89
|
futures = agents.each_with_index.map do |agent, index|
|
|
90
|
-
|
|
90
|
+
fire(:before_agent, agent, index)
|
|
91
91
|
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
92
92
|
future = Concurrent::Future.execute { agent.call }
|
|
93
93
|
[future, t0]
|
|
@@ -106,22 +106,22 @@ module ActiveHarness
|
|
|
106
106
|
value = future.value
|
|
107
107
|
result = value.is_a?(ActiveHarness::Agent) ? value.result : value
|
|
108
108
|
@results << result
|
|
109
|
-
|
|
109
|
+
fire(:after_agent, result, index)
|
|
110
110
|
elsif future.incomplete?
|
|
111
111
|
error = Errors::TimeoutError.new(
|
|
112
112
|
"Agent #{agents[index].class.name} timed out after #{@timeout}s"
|
|
113
113
|
)
|
|
114
114
|
@errors << { agent: agents[index].class.name, error: error }
|
|
115
|
-
|
|
115
|
+
fire(:agent_error, agents[index].class.name, error, index)
|
|
116
116
|
else
|
|
117
117
|
@errors << { agent: agents[index].class.name, error: future.reason }
|
|
118
|
-
|
|
118
|
+
fire(:agent_error, agents[index].class.name, future.reason, index)
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
@execution_time = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at).round(3)
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
fire(:after_call, @results, @errors)
|
|
125
125
|
|
|
126
126
|
# If all agents failed, raise an exception.
|
|
127
127
|
# Otherwise, compute the verdict based on successful results.
|
|
@@ -129,8 +129,8 @@ module ActiveHarness
|
|
|
129
129
|
|
|
130
130
|
verdict_input = transform_hook(:before_verdict, @results)
|
|
131
131
|
@verdict = compute_verdict(verdict_input)
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
|
|
133
|
+
fire(:after_verdict, @verdict)
|
|
134
134
|
|
|
135
135
|
self
|
|
136
136
|
end
|