bitfab 0.78.0 → 0.78.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8df415900dea564b2faa8d2ecc01c2538bf44ad2d88d16a669c54439cba933b6
4
- data.tar.gz: 262a531fc1566e6e276ec4f1b7136f09327fe6a2a97089f1e7f9fb067710937b
3
+ metadata.gz: 8745d019638e12c50bc8a25be073532ed2797ecda28dbc12bf714c66dab63e1c
4
+ data.tar.gz: bfc640b1369c86f80d66c4b05c682c0bffe9580268dcf8a1b122dd36ce789f06
5
5
  SHA512:
6
- metadata.gz: 05ead01bb8ece0e612217c20bd59f49233699735896f401db844430f0664c5bff188169185092f34bf7a01e2ba3d717f11738fc5e26066287e698cf87039e409
7
- data.tar.gz: 7ddc3c3294263875bdf80b9edb7ffc1eeadcda7e699f6b77c51135e606b5efcb950169584effdd303027aa1012de72ecd2699ac380c39ce1ad6784da56c23345
6
+ metadata.gz: 01a6b725a6fc64e6014610c3954f0830aa096719913d0ab79d42dcb4323563933f3dd9ee3e94db8ad9e68a3514258203761561adeda6becceaffbe387dee68b6
7
+ data.tar.gz: '09ac85589bcb180926d42563556c5c8f4a5859ebd8d24673cc1eda1ba51e203b43bf5df0b0113dafccdad1f2e74ae285799dc4c3da57fd34a3841e9c5d3b5128'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "json"
5
+ require "time"
6
+ require_relative "agent_session"
7
+
8
+ module Bitfab
9
+ module AgentSessionExperiments
10
+ SAFE_SESSION_ID = /\A[A-Za-z0-9_-][A-Za-z0-9._-]*\z/
11
+
12
+ module_function
13
+
14
+ def record(experiment_id:, experiment_url:, name:, service_url:, explicit_agent_session_id:)
15
+ session_id = session_id_for_path(explicit_agent_session_id)
16
+ return if session_id.nil?
17
+
18
+ directory = File.join(Dir.home, ".bitfab", "agent-sessions", session_id)
19
+ FileUtils.mkdir_p(directory)
20
+ line = JSON.generate(
21
+ experimentId: experiment_id,
22
+ experimentUrl: experiment_url,
23
+ name: name,
24
+ serviceUrl: service_url,
25
+ startedAt: Time.now.utc.iso8601(3)
26
+ )
27
+ File.open(File.join(directory, "experiments.jsonl"), "a") { |file| file.write("#{line}\n") }
28
+ nil
29
+ rescue
30
+ nil
31
+ end
32
+
33
+ def session_id_for_path(explicit)
34
+ session_id = AgentSession.resolve(explicit)
35
+ (session_id && SAFE_SESSION_ID.match?(session_id)) ? session_id : nil
36
+ rescue
37
+ nil
38
+ end
39
+ end
40
+ end
@@ -17,7 +17,9 @@ module Bitfab
17
17
  # latest check of its text (the same hash a save returns), or nil when no
18
18
  # check ever ran on it. Read a "pending" check from a save back here once
19
19
  # it finishes, and save each of its "separateAssertions" as its own
20
- # assertion.
20
+ # assertion. "codeHints" holds pointers for whoever writes code to check
21
+ # the assertion (span names, field paths, which span holds the answer), or
22
+ # nil when there are none; the LLM judge never reads them.
21
23
  def get_assertions(trace_id)
22
24
  response = @http_client.get(assertions_path(trace_id))
23
25
  return response unless response.is_a?(Hash) && response["assertions"].is_a?(Array)
@@ -54,6 +56,19 @@ module Bitfab
54
56
  # is off, and new code leaves the setting as it is. Removing the code turns
55
57
  # it back on. Omit "codeOff" to keep the current setting.
56
58
  #
59
+ # "codeHints" holds pointers for whoever writes code to check the
60
+ # assertion: span names, field paths, which span holds the answer. The LLM
61
+ # judge never reads them, so never put a requirement there: it belongs in
62
+ # "assertion". Omit "codeHints" to keep the current hints, or send an empty
63
+ # string or nil to clear them. Changing only the hints does not return the
64
+ # assertion to draft. Returned assertions carry "codeHints", nil when there
65
+ # are none.
66
+ #
67
+ # "passCriteria" and "failCriteria" are deprecated: write the assertion
68
+ # specific enough to need no criteria, and put where to look in
69
+ # "codeHints". They are still accepted, still returned, and the LLM judge
70
+ # still reads them on an assertion that has them.
71
+ #
57
72
  # "kind" => "external" creates an assertion Bitfab never judges: your own
58
73
  # system posts each verdict with VerdictsClient#save_external, and it takes
59
74
  # no "code". Send it only on the save that creates the assertion; a
@@ -49,6 +49,13 @@ LEGACY_KEY_SECRET_REFERENCE = re.compile(
49
49
  + r"\"?[ \t]*:[ \t]*[\"']?\$\{\{\s*secrets\[\s*format\(.*$"
50
50
  )
51
51
  DEFAULT_SERVICE_URL = "https://bitfab.ai"
52
+ LAUNCH_ID_METADATA_KEY = "bitfab-launch-id"
53
+ AGENT_SESSION_ENV_VARS = (
54
+ "CLAUDE_CODE_SESSION_ID",
55
+ "CODEX_THREAD_ID",
56
+ "AGENT_SESSION_ID",
57
+ )
58
+ SAFE_AGENT_SESSION_ID = re.compile(r"^[A-Za-z0-9_-][A-Za-z0-9._-]*$")
52
59
  OIDC_AUDIENCE = "bitfab-cloud-replay"
53
60
  ID_TOKEN_PERMISSION = re.compile(
54
61
  r"^[ \t]*(\"?id-token\"?[ \t]*:[ \t]*[\"']?write[\"']?|\"?permissions\"?[ \t]*:[ \t]*[\"']?write-all[\"']?)[ \t]*(#.*)?$",
@@ -899,6 +906,59 @@ def check_arguments(replay):
899
906
  )
900
907
 
901
908
 
909
+ def replay_flag_value(replay, flag):
910
+ for index, token in enumerate(replay):
911
+ name, separator, value = token.partition("=")
912
+ if name != flag:
913
+ continue
914
+ if separator:
915
+ return value
916
+ if index + 1 < len(replay):
917
+ return replay[index + 1]
918
+ return None
919
+
920
+
921
+ def launch_metadata_args(execution_id):
922
+ return ["--metadata", f"{LAUNCH_ID_METADATA_KEY}={execution_id}"]
923
+
924
+
925
+ def agent_session_id(replay):
926
+ explicit = (replay_flag_value(replay, "--agent-session-id") or "").strip()
927
+ if explicit:
928
+ return explicit
929
+ for name in AGENT_SESSION_ENV_VARS:
930
+ value = os.environ.get(name, "").strip()
931
+ if value and len(value) <= 255:
932
+ return value
933
+ return None
934
+
935
+
936
+ def record_agent_session_launch(parsed):
937
+ session_id = agent_session_id(parsed["replay"])
938
+ if session_id is None or not SAFE_AGENT_SESSION_ID.fullmatch(session_id):
939
+ return
940
+ try:
941
+ directory = Path.home() / ".bitfab" / "agent-sessions" / session_id
942
+ directory.mkdir(parents=True, exist_ok=True)
943
+ service_url = (
944
+ os.environ.get("BITFAB_SERVICE_URL", "").strip() or DEFAULT_SERVICE_URL
945
+ )
946
+ resumed = replay_flag_value(parsed["replay"], "--resume")
947
+ line = json.dumps(
948
+ {
949
+ "launchId": None if resumed else parsed["id"],
950
+ "experimentId": resumed,
951
+ "name": replay_flag_value(parsed["replay"], "--name"),
952
+ "serviceUrl": service_url.rstrip("/"),
953
+ "startedAt": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
954
+ }
955
+ )
956
+ with open(directory / "experiments.jsonl", "a", encoding="utf-8") as handle:
957
+ handle.write(line + "\n")
958
+ except Exception:
959
+ return
960
+
961
+
902
962
  def replay_request(root, parsed):
903
963
  cwd = Path.cwd().resolve()
904
964
  args, files = [], []
@@ -923,6 +983,8 @@ def replay_request(root, parsed):
923
983
  else:
924
984
  args.append(token)
925
985
  index += 1
986
+ if replay_flag_value(replay, "--resume") is None:
987
+ args += launch_metadata_args(parsed["id"])
926
988
  validate_arguments(args)
927
989
  request = {
928
990
  "version": REQUEST_VERSION
@@ -1998,6 +2060,8 @@ def run_cli(argv):
1998
2060
  raise
1999
2061
  if record.get("preview"):
2000
2062
  return record, None
2063
+ if record["state"] != "prepared":
2064
+ record_agent_session_launch(parsed)
2001
2065
  reason = record.pop("unfollowed", None)
2002
2066
  if reason:
2003
2067
  report_unfollowed(record, reason)
data/lib/bitfab/replay.rb CHANGED
@@ -5,6 +5,7 @@ require "json"
5
5
  require "open3"
6
6
  require "timeout"
7
7
 
8
+ require_relative "agent_session_experiments"
8
9
  require_relative "constants"
9
10
  require_relative "git_command"
10
11
  require_relative "mock_override"
@@ -477,6 +478,12 @@ module Bitfab
477
478
  experiment_url = replay_data["experimentUrl"] || replay_data["testRunUrl"]
478
479
  # Nil for a dry run: current servers create no experiment for one.
479
480
  full_experiment_url = experiment_url && "#{client.service_url}#{experiment_url}"
481
+ if experiment_id && full_experiment_url
482
+ AgentSessionExperiments.record(
483
+ experiment_id:, experiment_url: full_experiment_url, name:,
484
+ service_url: client.service_url, explicit_agent_session_id: agent_session_id
485
+ )
486
+ end
480
487
  if on_experiment_start && experiment_id
481
488
  begin
482
489
  on_experiment_start.call({experiment_id:, experiment_url: full_experiment_url})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.78.0"
4
+ VERSION = "0.78.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.78.0
4
+ version: 0.78.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team
@@ -170,6 +170,7 @@ files:
170
170
  - exe/bitfab-seed
171
171
  - lib/bitfab.rb
172
172
  - lib/bitfab/agent_session.rb
173
+ - lib/bitfab/agent_session_experiments.rb
173
174
  - lib/bitfab/assertions.rb
174
175
  - lib/bitfab/baml.rb
175
176
  - lib/bitfab/categories.rb