bitfab 0.75.5 → 0.76.1
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/bitfab/assertions.rb +6 -0
- data/lib/bitfab/client.rb +6 -2
- data/lib/bitfab/span_context.rb +17 -0
- data/lib/bitfab/spans.rb +28 -1
- data/lib/bitfab/subtree.rb +4 -1
- data/lib/bitfab/verdicts.rb +28 -0
- data/lib/bitfab/version.rb +1 -1
- data/lib/bitfab.rb +3 -0
- 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: f272aee3a4e633dffcc3b05633f62a5e2f51c629fd06cc39e1999eadd870dc5f
|
|
4
|
+
data.tar.gz: 96f0ca223998a9a8b26c13fc3cd161e2eee815e322190f19ffeabe6b8f1e930b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfd82ea9b07e7395db282e94636470b7c530076298cd06bab9e2d6f8510fec42279084ce86c1aa39dd88e0c7abf04d9bf7b5b774659e92a40397f45c451b49fe
|
|
7
|
+
data.tar.gz: d550786d6876ec1a4d782f841b915f4a871e0cc517e75ebc92f4f5001f40dd84670375b367b1ad0818f073046b1a1be0c1c1414af203458549002c8973403338
|
data/lib/bitfab/assertions.rb
CHANGED
|
@@ -54,6 +54,12 @@ module Bitfab
|
|
|
54
54
|
# is off, and new code leaves the setting as it is. Removing the code turns
|
|
55
55
|
# it back on. Omit "codeOff" to keep the current setting.
|
|
56
56
|
#
|
|
57
|
+
# "kind" => "external" creates an assertion Bitfab never judges: your own
|
|
58
|
+
# system posts each verdict with VerdictsClient#save_external, and it takes
|
|
59
|
+
# no "code". Send it only on the save that creates the assertion; a
|
|
60
|
+
# different kind on an edit is refused, so omit it there. Returned
|
|
61
|
+
# assertions carry "kind": "bitfab" (Bitfab decides it) or "external".
|
|
62
|
+
#
|
|
57
63
|
# By default, after the save, Bitfab checks each assertion's text against its
|
|
58
64
|
# trace. When the text bundles two claims, adds a condition, points at a
|
|
59
65
|
# value instead of stating it, names an id from the recorded run, or cannot
|
data/lib/bitfab/client.rb
CHANGED
|
@@ -601,6 +601,7 @@ module Bitfab
|
|
|
601
601
|
error = nil
|
|
602
602
|
span_contexts = nil
|
|
603
603
|
span_prompt = nil
|
|
604
|
+
span_metadata = nil
|
|
604
605
|
completed = false
|
|
605
606
|
@http_client.trace_completion.start(trace_id, span_id)
|
|
606
607
|
recording_override = managed_root ? {} : nil
|
|
@@ -638,7 +639,7 @@ module Bitfab
|
|
|
638
639
|
end
|
|
639
640
|
|
|
640
641
|
on_complete&.call(result: recorded_result, error: recorded_error, ended_at:,
|
|
641
|
-
contexts: span_contexts, prompt: span_prompt)
|
|
642
|
+
contexts: span_contexts, prompt: span_prompt, metadata: span_metadata)
|
|
642
643
|
|
|
643
644
|
span_data = span_data.merge("replay_reusable" => replay_reusable)
|
|
644
645
|
output_json = finalize.nil? && !result.is_a?(Enumerator) && SelectiveReplay.fingerprint(final_result)
|
|
@@ -662,6 +663,7 @@ module Bitfab
|
|
|
662
663
|
function_name: recording_override&.dig(:function_name) || function_name,
|
|
663
664
|
contexts: span_contexts,
|
|
664
665
|
prompt: span_prompt,
|
|
666
|
+
metadata: span_metadata,
|
|
665
667
|
args:,
|
|
666
668
|
kwargs:,
|
|
667
669
|
result: recorded_result,
|
|
@@ -740,6 +742,7 @@ module Bitfab
|
|
|
740
742
|
# Capture contexts before the span context is popped
|
|
741
743
|
span_contexts = SpanContext.current&.dig(:contexts)
|
|
742
744
|
span_prompt = SpanContext.current&.dig(:prompt)
|
|
745
|
+
span_metadata = SpanContext.current&.dig(:metadata)
|
|
743
746
|
end
|
|
744
747
|
end
|
|
745
748
|
rescue => e
|
|
@@ -1049,7 +1052,7 @@ module Bitfab
|
|
|
1049
1052
|
|
|
1050
1053
|
def send_span(trace_function_key:, trace_id:, span_id:, parent_span_id:,
|
|
1051
1054
|
span_name:, span_type:, function_name:, contexts:, prompt:, args:, kwargs:, result:, error:,
|
|
1052
|
-
started_at:, ended_at:, experiment_id: nil, input_source_span_id: nil, mocked: false,
|
|
1055
|
+
started_at:, ended_at:, metadata: nil, experiment_id: nil, input_source_span_id: nil, mocked: false,
|
|
1053
1056
|
mock_target: nil, mock_source: nil, span_data: {}, instrumentation: "span", declared_node: false,
|
|
1054
1057
|
nearest_captured_ancestor_span_id: nil)
|
|
1055
1058
|
extra_span_data = span_data
|
|
@@ -1100,6 +1103,7 @@ module Bitfab
|
|
|
1100
1103
|
end
|
|
1101
1104
|
span_data["contexts"] = contexts if contexts&.any?
|
|
1102
1105
|
span_data["prompt"] = prompt if prompt && !content_off
|
|
1106
|
+
span_data["metadata"] = metadata if metadata&.any?
|
|
1103
1107
|
|
|
1104
1108
|
raw_span = {
|
|
1105
1109
|
"id" => span_id,
|
data/lib/bitfab/span_context.rb
CHANGED
|
@@ -55,6 +55,23 @@ module Bitfab
|
|
|
55
55
|
rescue
|
|
56
56
|
# Silently ignore - never crash the host app
|
|
57
57
|
end
|
|
58
|
+
|
|
59
|
+
# Merge metadata into this span, with later values for a key winning. Use
|
|
60
|
+
# it to label what the span did, for example { "delivery" => "blocked" } on
|
|
61
|
+
# a message that was drafted but never sent. Values must be strings,
|
|
62
|
+
# numbers, or booleans; keys are 1 to 40 of A-Z a-z 0-9 _ . : -. Bitfab
|
|
63
|
+
# stores keys and values lowercased, returns them on spans.list, and
|
|
64
|
+
# narrows that list with its metadata filter. Sent even when content
|
|
65
|
+
# capture is off, like trace metadata.
|
|
66
|
+
#
|
|
67
|
+
# @param metadata [Hash] key-value pairs to merge into the span's metadata
|
|
68
|
+
def set_metadata(metadata)
|
|
69
|
+
return unless metadata.is_a?(Hash)
|
|
70
|
+
|
|
71
|
+
@span_state[:metadata] = (@span_state[:metadata] || {}).merge(metadata)
|
|
72
|
+
rescue
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
58
75
|
end
|
|
59
76
|
|
|
60
77
|
# Handle to the current active trace, allowing trace-level context to be set.
|
data/lib/bitfab/spans.rb
CHANGED
|
@@ -2,18 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
module Bitfab
|
|
4
4
|
class Spans
|
|
5
|
+
MAX_PAGE_SIZE = 200
|
|
6
|
+
MAX_PAGE_SIZE_WITH_FIELDS = 50
|
|
7
|
+
private_constant :MAX_PAGE_SIZE, :MAX_PAGE_SIZE_WITH_FIELDS
|
|
8
|
+
|
|
5
9
|
def initialize(http_client)
|
|
6
10
|
@http_client = http_client
|
|
7
11
|
end
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
# One page of a trace's spans in the order they ran. Each span carries its
|
|
14
|
+
# "metadata" Hash, keys and values lowercased, empty when none was set.
|
|
15
|
+
# metadata: keeps only spans whose metadata holds every given key with that
|
|
16
|
+
# value, matched exactly and case-insensitively, up to 10 keys. limit is 1
|
|
17
|
+
# to 200, or at most 50 when fields are requested; a larger value raises
|
|
18
|
+
# with the server's reason. Use list_all to read every span.
|
|
19
|
+
def list(trace_id, span_type: nil, span_name: nil, metadata: nil, fields: nil, cursor: nil, limit: nil)
|
|
10
20
|
payload = {"traceId" => trace_id}
|
|
11
21
|
payload["spanType"] = span_type unless span_type.nil?
|
|
12
22
|
payload["spanName"] = span_name unless span_name.nil?
|
|
23
|
+
payload["metadata"] = metadata unless metadata.nil?
|
|
13
24
|
payload["fields"] = fields unless fields.nil?
|
|
14
25
|
payload["cursor"] = cursor unless cursor.nil?
|
|
15
26
|
payload["limit"] = limit unless limit.nil?
|
|
16
27
|
@http_client.request("/api/sdk/spans/list", payload)
|
|
17
28
|
end
|
|
29
|
+
|
|
30
|
+
# Every span of one trace in the order they ran, fetched page by page until
|
|
31
|
+
# none are left. Takes the same filters as list. Pages hold 200 spans, or 50
|
|
32
|
+
# when fields are requested.
|
|
33
|
+
def list_all(trace_id, span_type: nil, span_name: nil, metadata: nil, fields: nil)
|
|
34
|
+
limit = (fields.nil? || fields.empty?) ? MAX_PAGE_SIZE : MAX_PAGE_SIZE_WITH_FIELDS
|
|
35
|
+
spans = []
|
|
36
|
+
cursor = nil
|
|
37
|
+
loop do
|
|
38
|
+
page = list(trace_id, span_type:, span_name:, metadata:, fields:, cursor:, limit:)
|
|
39
|
+
spans.concat(page["spans"] || [])
|
|
40
|
+
cursor = page["hasMore"] ? page["nextCursor"] : nil
|
|
41
|
+
break if cursor.nil?
|
|
42
|
+
end
|
|
43
|
+
spans
|
|
44
|
+
end
|
|
18
45
|
end
|
|
19
46
|
end
|
data/lib/bitfab/subtree.rb
CHANGED
|
@@ -54,6 +54,7 @@ module Bitfab
|
|
|
54
54
|
:declared_node,
|
|
55
55
|
:contexts,
|
|
56
56
|
:prompt,
|
|
57
|
+
:metadata,
|
|
57
58
|
:jev_started_at,
|
|
58
59
|
:jev_recorded_below
|
|
59
60
|
)
|
|
@@ -152,7 +153,7 @@ module Bitfab
|
|
|
152
153
|
span_id: @owner.current_parent_span_id, surface: :trace, &body)
|
|
153
154
|
end
|
|
154
155
|
|
|
155
|
-
def complete(result:, error:, ended_at:, contexts: nil, prompt: nil)
|
|
156
|
+
def complete(result:, error:, ended_at:, contexts: nil, prompt: nil, metadata: nil)
|
|
156
157
|
return if @completed
|
|
157
158
|
|
|
158
159
|
@completed = true
|
|
@@ -162,6 +163,7 @@ module Bitfab
|
|
|
162
163
|
entry.error = error
|
|
163
164
|
entry.contexts = contexts
|
|
164
165
|
entry.prompt = prompt
|
|
166
|
+
entry.metadata = metadata
|
|
165
167
|
session.emit_configured(entry, result:)
|
|
166
168
|
end
|
|
167
169
|
end
|
|
@@ -767,6 +769,7 @@ module Bitfab
|
|
|
767
769
|
function_name: entry.name,
|
|
768
770
|
contexts: entry.contexts,
|
|
769
771
|
prompt: entry.prompt,
|
|
772
|
+
metadata: entry.metadata,
|
|
770
773
|
args: entry.args,
|
|
771
774
|
kwargs: entry.kwargs,
|
|
772
775
|
result:,
|
data/lib/bitfab/verdicts.rb
CHANGED
|
@@ -97,6 +97,7 @@ module Bitfab
|
|
|
97
97
|
class Verdicts
|
|
98
98
|
VERDICTS_PATH = "/api/sdk/traces/verdicts"
|
|
99
99
|
HUMAN_VERDICTS_PATH = "#{VERDICTS_PATH}/human"
|
|
100
|
+
EXTERNAL_VERDICTS_PATH = "#{VERDICTS_PATH}/external"
|
|
100
101
|
# @deprecated Use {VERDICTS_PATH}.
|
|
101
102
|
LABELS_PATH = VERDICTS_PATH
|
|
102
103
|
# @deprecated Use {HUMAN_VERDICTS_PATH}.
|
|
@@ -194,6 +195,29 @@ module Bitfab
|
|
|
194
195
|
end
|
|
195
196
|
end
|
|
196
197
|
|
|
198
|
+
# Saves your own system's verdict on an external assertion: one created with "kind" => "external",
|
|
199
|
+
# which Bitfab never judges. It names only the assertion; Bitfab finds the trace the assertion is on.
|
|
200
|
+
# +verdict:+ is "pass" or "fail". It counts in every pass rate as soon as it is saved, and a person's
|
|
201
|
+
# or an agent's verdict on the same assertion still counts over it. Pass +experiment_id:+ (and
|
|
202
|
+
# +attempt:+ when the experiment ran each trace more than once) to save it on that experiment's
|
|
203
|
+
# replay of the assertion's trace instead.
|
|
204
|
+
def save_external(assertion_id:, verdict:, annotation: nil, confidence: nil, evidence: EVIDENCE_UNSET,
|
|
205
|
+
experiment_id: nil, attempt: nil)
|
|
206
|
+
update = {"assertionId" => assertion_id, "verdict" => verdict}
|
|
207
|
+
update["attempt"] = attempt unless attempt.nil?
|
|
208
|
+
update["annotation"] = annotation unless annotation.nil?
|
|
209
|
+
update["confidence"] = confidence unless confidence.nil?
|
|
210
|
+
update["evidence"] = evidence unless evidence.equal?(EVIDENCE_UNSET)
|
|
211
|
+
save_external_all([update], experiment_id:).first
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Saves several external assertion verdicts in one all-or-nothing request.
|
|
215
|
+
def save_external_all(verdicts, experiment_id: nil)
|
|
216
|
+
body = {"verdicts" => verdicts}
|
|
217
|
+
body["experimentId"] = experiment_id unless experiment_id.nil?
|
|
218
|
+
@http_client.request(EXTERNAL_VERDICTS_PATH, body)["verdicts"]
|
|
219
|
+
end
|
|
220
|
+
|
|
197
221
|
# Reads one trace's verdicts, or nil when the trace has none. See {#get_all} for the shape of each
|
|
198
222
|
# "evidence" item.
|
|
199
223
|
def get(trace_id)
|
|
@@ -203,6 +227,10 @@ module Bitfab
|
|
|
203
227
|
# Reads the verdicts of several traces. Each trace and each entry of its "assertions" carries
|
|
204
228
|
# "evidence": nil, or an array of hashes, one per span cited, each with "spanId" and "text".
|
|
205
229
|
#
|
|
230
|
+
# An assertion can carry one entry per source. "counted" is true on the one that counts toward the
|
|
231
|
+
# trace's verdict: a person's counts over a coding agent's, and a coding agent's over Bitfab's
|
|
232
|
+
# judge's, which then reads "counted" false.
|
|
233
|
+
#
|
|
206
234
|
# Evidence written by Bitfab's assertion judge also carries "field", "ranges", and "spanChanged",
|
|
207
235
|
# which point at the exact passages the judge read. "field" is the span field the judge read
|
|
208
236
|
# ("summary", "input", "output", "reasoning", "content", "metadata", "errors", "contexts", or
|
data/lib/bitfab/version.rb
CHANGED
data/lib/bitfab.rb
CHANGED