@bitfab/sdk 0.52.3 → 0.52.5

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.
Files changed (35) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-SECFVEQV.js → chunk-BEAGKWXY.js} +291 -21
  3. package/dist/chunk-BEAGKWXY.js.map +1 -0
  4. package/dist/{chunk-ODF4JSYX.js → chunk-IHAB7SPF.js} +15 -2
  5. package/dist/{chunk-ODF4JSYX.js.map → chunk-IHAB7SPF.js.map} +1 -1
  6. package/dist/chunk-ITIMJ24H.js +747 -0
  7. package/dist/chunk-ITIMJ24H.js.map +1 -0
  8. package/dist/{chunk-45SK3FUL.js → chunk-THKLMOHS.js} +111 -13
  9. package/dist/chunk-THKLMOHS.js.map +1 -0
  10. package/dist/{chunk-QHA46TT6.js → chunk-VAIXHJ7O.js} +14 -2
  11. package/dist/{chunk-QHA46TT6.js.map → chunk-VAIXHJ7O.js.map} +1 -1
  12. package/dist/{http-ZW5THLTW.js → http-6Y3IQQ2Z.js} +2 -2
  13. package/dist/{http-3MPIPYKC.js → http-KZU56HZA.js} +2 -2
  14. package/dist/index.cjs +444 -57
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +44 -2
  17. package/dist/index.d.ts +44 -2
  18. package/dist/index.js +5 -3
  19. package/dist/node.cjs +444 -57
  20. package/dist/node.cjs.map +1 -1
  21. package/dist/node.d.cts +1 -1
  22. package/dist/node.d.ts +1 -1
  23. package/dist/node.js +5 -3
  24. package/dist/node.js.map +1 -1
  25. package/dist/{replay-W5SAHEU5.js → replay-LZ7DIY5L.js} +5 -3
  26. package/dist/replayCli.js +18 -687
  27. package/dist/replayCli.js.map +1 -1
  28. package/dist/seedCli.js +30 -0
  29. package/dist/seedCli.js.map +1 -0
  30. package/package.json +3 -2
  31. package/dist/chunk-45SK3FUL.js.map +0 -1
  32. package/dist/chunk-SECFVEQV.js.map +0 -1
  33. /package/dist/{http-3MPIPYKC.js.map → http-6Y3IQQ2Z.js.map} +0 -0
  34. /package/dist/{http-ZW5THLTW.js.map → http-KZU56HZA.js.map} +0 -0
  35. /package/dist/{replay-W5SAHEU5.js.map → replay-LZ7DIY5L.js.map} +0 -0
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.52.3";
91
+ __version__ = "0.52.5";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -1128,7 +1128,7 @@ var init_otel = __esm({
1128
1128
  if (this.onDelivered === void 0) {
1129
1129
  return;
1130
1130
  }
1131
- const refs = spans.map((span) => span.ref).filter((ref) => ref !== void 0);
1131
+ const refs = spans.map((span) => span.ref).filter((ref2) => ref2 !== void 0);
1132
1132
  if (refs.length === 0) {
1133
1133
  return;
1134
1134
  }
@@ -1385,9 +1385,9 @@ function parseRetryAfterMs(header) {
1385
1385
  }
1386
1386
  return Math.max(0, at - Date.now());
1387
1387
  }
1388
- function carrierMeta(operation, payload, ref) {
1388
+ function carrierMeta(operation, payload, ref2) {
1389
1389
  return {
1390
- ref,
1390
+ ref: ref2,
1391
1391
  name: carrierName(operation, payload),
1392
1392
  startTime: payloadTimestamp(payload, "started_at"),
1393
1393
  endTime: payloadTimestamp(payload, "ended_at"),
@@ -1632,22 +1632,22 @@ var init_http = __esm({
1632
1632
  return reports;
1633
1633
  }
1634
1634
  /** Build a carrier's meta and record what it adds to its trace's expected set. */
1635
- recordedMeta(operation, payload, ref) {
1636
- this.recordSubmittedCarrier(ref);
1637
- return carrierMeta(operation, payload, ref);
1635
+ recordedMeta(operation, payload, ref2) {
1636
+ this.recordSubmittedCarrier(ref2);
1637
+ return carrierMeta(operation, payload, ref2);
1638
1638
  }
1639
- recordSubmittedCarrier(ref) {
1640
- if (ref === void 0) {
1639
+ recordSubmittedCarrier(ref2) {
1640
+ if (ref2 === void 0) {
1641
1641
  return;
1642
1642
  }
1643
- const delivery = this.traceDeliveries.get(ref.traceId);
1643
+ const delivery = this.traceDeliveries.get(ref2.traceId);
1644
1644
  if (delivery === void 0) {
1645
1645
  return;
1646
1646
  }
1647
- if (ref.spanId === void 0) {
1647
+ if (ref2.spanId === void 0) {
1648
1648
  delivery.closed = true;
1649
1649
  } else {
1650
- delivery.submittedSpanIds.add(ref.spanId);
1650
+ delivery.submittedSpanIds.add(ref2.spanId);
1651
1651
  }
1652
1652
  }
1653
1653
  /**
@@ -1673,15 +1673,15 @@ var init_http = __esm({
1673
1673
  }
1674
1674
  }
1675
1675
  recordDeliveredCarriers(refs) {
1676
- for (const ref of refs) {
1677
- const delivery = this.traceDeliveries.get(ref.traceId);
1676
+ for (const ref2 of refs) {
1677
+ const delivery = this.traceDeliveries.get(ref2.traceId);
1678
1678
  if (delivery === void 0) {
1679
1679
  continue;
1680
1680
  }
1681
- if (ref.spanId === void 0) {
1681
+ if (ref2.spanId === void 0) {
1682
1682
  delivery.closingAcked = true;
1683
1683
  } else {
1684
- delivery.ackedSpanIds.add(ref.spanId);
1684
+ delivery.ackedSpanIds.add(ref2.spanId);
1685
1685
  }
1686
1686
  }
1687
1687
  }
@@ -1711,9 +1711,9 @@ var init_http = __esm({
1711
1711
  */
1712
1712
  async waitForPendingRequests(timeoutMs = DEFAULT_LIFECYCLE_TIMEOUT_MS2) {
1713
1713
  const deadline = Date.now() + Math.max(timeoutMs, 0);
1714
- const settled = await this.settleDeferredWork(timeoutMs);
1714
+ const settled2 = await this.settleDeferredWork(timeoutMs);
1715
1715
  const flushed = await this.traceTransport?.flush(Math.max(0, deadline - Date.now())) ?? true;
1716
- return settled && flushed;
1716
+ return settled2 && flushed;
1717
1717
  }
1718
1718
  /**
1719
1719
  * Flush and permanently close this client's tracing transport. Idempotent:
@@ -1726,14 +1726,14 @@ var init_http = __esm({
1726
1726
  }
1727
1727
  const deadline = Date.now() + Math.max(timeoutMs, 0);
1728
1728
  this.closing = (async () => {
1729
- const settled = await this.settleDeferredWork(
1729
+ const settled2 = await this.settleDeferredWork(
1730
1730
  Math.max(0, deadline - Date.now())
1731
1731
  );
1732
1732
  this.closed = true;
1733
1733
  const transport = this.traceTransport;
1734
1734
  this.traceTransport = void 0;
1735
1735
  const shutdownOk = await transport?.shutdown(Math.max(0, deadline - Date.now())) ?? true;
1736
- return settled && shutdownOk;
1736
+ return settled2 && shutdownOk;
1737
1737
  })();
1738
1738
  return this.closing;
1739
1739
  }
@@ -2122,6 +2122,18 @@ var init_http = __esm({
2122
2122
  { timeout: REPLAY_COMPLETE_REQUEST_TIMEOUT_MS }
2123
2123
  );
2124
2124
  }
2125
+ async getReseedSource(traceId) {
2126
+ return this.get(
2127
+ `/api/sdk/traces/${encodeURIComponent(traceId)}/reseedSource`
2128
+ );
2129
+ }
2130
+ async reseedTrace(traceId, runTraceId) {
2131
+ return this.request(
2132
+ `/api/sdk/traces/${encodeURIComponent(traceId)}/reseed`,
2133
+ { runTraceId },
2134
+ { timeout: 3e4 }
2135
+ );
2136
+ }
2125
2137
  /**
2126
2138
  * Ask the server to materialize a per-trace DB branch lease from a
2127
2139
  * captured `dbSnapshotRef`. Blocking - the resolver creates a Neon
@@ -2332,6 +2344,112 @@ var init_randomUuid = __esm({
2332
2344
  }
2333
2345
  });
2334
2346
 
2347
+ // src/gitCommand.ts
2348
+ function isUnrefable(value) {
2349
+ return typeof value === "object" && value !== null && "unref" in value && typeof value.unref === "function";
2350
+ }
2351
+ function unrefStream(stream) {
2352
+ if (isUnrefable(stream)) {
2353
+ stream.unref();
2354
+ }
2355
+ }
2356
+ function terminate(child) {
2357
+ if (child.pid && process.platform !== "win32") {
2358
+ try {
2359
+ process.kill(-child.pid, "SIGTERM");
2360
+ return;
2361
+ } catch {
2362
+ child.kill("SIGTERM");
2363
+ return;
2364
+ }
2365
+ }
2366
+ child.kill("SIGTERM");
2367
+ }
2368
+ async function gitRunner(options) {
2369
+ let spawn;
2370
+ try {
2371
+ ;
2372
+ ({ spawn } = await import("child_process"));
2373
+ } catch {
2374
+ return null;
2375
+ }
2376
+ return (dir, args) => new Promise((resolve) => {
2377
+ let child;
2378
+ try {
2379
+ child = spawn("git", args, {
2380
+ cwd: dir,
2381
+ detached: process.platform !== "win32",
2382
+ stdio: ["ignore", "pipe", "pipe"]
2383
+ });
2384
+ } catch {
2385
+ resolve(null);
2386
+ return;
2387
+ }
2388
+ const chunks = [];
2389
+ let size = 0;
2390
+ let overflow = false;
2391
+ let exitCode = null;
2392
+ let done = false;
2393
+ const timers = [];
2394
+ const schedule = (callback, ms) => {
2395
+ const timer = setTimeout(callback, ms);
2396
+ if (!options.keepProcessAlive) {
2397
+ timer.unref();
2398
+ }
2399
+ timers.push(timer);
2400
+ };
2401
+ const finish = () => {
2402
+ if (done) {
2403
+ return;
2404
+ }
2405
+ done = true;
2406
+ for (const timer of timers) {
2407
+ clearTimeout(timer);
2408
+ }
2409
+ child.stdout?.destroy();
2410
+ child.stderr?.destroy();
2411
+ resolve(
2412
+ exitCode === 0 && !overflow ? Buffer.concat(chunks).toString("utf8") : null
2413
+ );
2414
+ };
2415
+ child.stdout?.on("data", (chunk) => {
2416
+ size += chunk.length;
2417
+ if (size > options.maxBuffer) {
2418
+ overflow = true;
2419
+ terminate(child);
2420
+ return;
2421
+ }
2422
+ chunks.push(chunk);
2423
+ });
2424
+ child.stderr?.resume();
2425
+ child.on("error", () => {
2426
+ exitCode = null;
2427
+ finish();
2428
+ });
2429
+ child.on("exit", (code) => {
2430
+ exitCode = code;
2431
+ schedule(finish, EXIT_GRACE_MS);
2432
+ });
2433
+ child.on("close", (code) => {
2434
+ exitCode = code ?? exitCode;
2435
+ finish();
2436
+ });
2437
+ schedule(() => terminate(child), options.timeoutMs);
2438
+ if (!options.keepProcessAlive) {
2439
+ child.unref();
2440
+ unrefStream(child.stdout);
2441
+ unrefStream(child.stderr);
2442
+ }
2443
+ });
2444
+ }
2445
+ var EXIT_GRACE_MS;
2446
+ var init_gitCommand = __esm({
2447
+ "src/gitCommand.ts"() {
2448
+ "use strict";
2449
+ EXIT_GRACE_MS = 500;
2450
+ }
2451
+ });
2452
+
2335
2453
  // src/mockOverride.ts
2336
2454
  function resolveMockValue(value, ctx) {
2337
2455
  return typeof value === "function" ? value(ctx) : value;
@@ -2388,37 +2506,33 @@ async function readCodeChangeFile() {
2388
2506
  }
2389
2507
  }
2390
2508
  async function captureCodeChangeFromGit(cwd, label) {
2391
- let execFile;
2392
2509
  let readFile;
2393
2510
  try {
2394
2511
  ;
2395
- ({ execFile } = await import("child_process"));
2396
2512
  ({ readFile } = await import("fs/promises"));
2397
2513
  } catch {
2398
2514
  return null;
2399
2515
  }
2400
- const git = (dir, args) => new Promise((resolve) => {
2401
- execFile(
2402
- "git",
2403
- args,
2404
- // 30s timeout so a hung git (e.g. a network-touching ref op) can't
2405
- // block the whole replay indefinitely.
2406
- { cwd: dir, maxBuffer: 64 * 1024 * 1024, timeout: 3e4 },
2407
- (err, stdout) => resolve(err ? null : stdout)
2408
- );
2516
+ const git = await gitRunner({
2517
+ timeoutMs: 3e4,
2518
+ maxBuffer: 64 * 1024 * 1024,
2519
+ keepProcessAlive: true
2409
2520
  });
2521
+ if (!git) {
2522
+ return null;
2523
+ }
2410
2524
  try {
2411
2525
  const root = (await git(cwd, ["rev-parse", "--show-toplevel"]))?.trim();
2412
2526
  if (!root) {
2413
2527
  return null;
2414
2528
  }
2415
- const resolved = await resolveBase(git, root);
2416
- if (!resolved) {
2529
+ const resolved2 = await resolveBase(git, root);
2530
+ if (!resolved2) {
2417
2531
  return null;
2418
2532
  }
2419
- const { base, fromTrunk } = resolved;
2420
- const blobBytes = async (ref, path) => {
2421
- const out = await git(root, ["cat-file", "-s", `${ref}:${path}`]);
2533
+ const { base, fromTrunk } = resolved2;
2534
+ const blobBytes = async (ref2, path) => {
2535
+ const out = await git(root, ["cat-file", "-s", `${ref2}:${path}`]);
2422
2536
  const n = out ? Number.parseInt(out.trim(), 10) : Number.NaN;
2423
2537
  return Number.isFinite(n) ? n : 0;
2424
2538
  };
@@ -2510,8 +2624,8 @@ async function resolveBase(git, root) {
2510
2624
  }
2511
2625
  return await refExists(git, root, "HEAD") ? { base: "HEAD", fromTrunk: false } : null;
2512
2626
  }
2513
- async function refExists(git, root, ref) {
2514
- return await git(root, ["rev-parse", "--verify", `${ref}^{object}`]) !== null;
2627
+ async function refExists(git, root, ref2) {
2628
+ return await git(root, ["rev-parse", "--verify", `${ref2}^{object}`]) !== null;
2515
2629
  }
2516
2630
  async function readWorkingFile(readFile, root, path) {
2517
2631
  try {
@@ -2546,6 +2660,7 @@ var MAX_FILES, MAX_FILE_BYTES, MAX_TOTAL_BYTES, TRUNK_CANDIDATES, NUL;
2546
2660
  var init_codeChange = __esm({
2547
2661
  "src/codeChange.ts"() {
2548
2662
  "use strict";
2663
+ init_gitCommand();
2549
2664
  MAX_FILES = 60;
2550
2665
  MAX_FILE_BYTES = 5e5;
2551
2666
  MAX_TOTAL_BYTES = 2e6;
@@ -2566,6 +2681,7 @@ __export(replay_exports, {
2566
2681
  BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
2567
2682
  DbBranchReplayError: () => DbBranchReplayError,
2568
2683
  ReplayError: () => ReplayError,
2684
+ deserializeInputs: () => deserializeInputs,
2569
2685
  replay: () => replay,
2570
2686
  reportReplayProgress: () => reportReplayProgress,
2571
2687
  serializeReplayResult: () => serializeReplayResult,
@@ -2749,9 +2865,9 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2749
2865
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
2750
2866
  try {
2751
2867
  if (includeDbBranchLease && !lease && !leaseError) {
2752
- let resolved;
2868
+ let resolved2;
2753
2869
  try {
2754
- resolved = await httpClient.resolveDbBranchLease(
2870
+ resolved2 = await httpClient.resolveDbBranchLease(
2755
2871
  testRunId,
2756
2872
  originalTraceId,
2757
2873
  dbBranchSettings,
@@ -2765,10 +2881,10 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2765
2881
  cause
2766
2882
  );
2767
2883
  }
2768
- lease = resolved.lease ?? void 0;
2769
- leaseError = resolved.leaseError ?? void 0;
2770
- dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
2771
- dbBranchTimings = resolved.timings ?? dbBranchTimings;
2884
+ lease = resolved2.lease ?? void 0;
2885
+ leaseError = resolved2.leaseError ?? void 0;
2886
+ dbSnapshotRef = resolved2.dbSnapshotRef ?? dbSnapshotRef;
2887
+ dbBranchTimings = resolved2.timings ?? dbBranchTimings;
2772
2888
  }
2773
2889
  if (leaseError) {
2774
2890
  throw new DbBranchReplayError(
@@ -3416,6 +3532,7 @@ __export(node_exports, {
3416
3532
  getCurrentSpan: () => getCurrentSpan,
3417
3533
  getCurrentTrace: () => getCurrentTrace,
3418
3534
  reportReplayProgress: () => reportReplayProgress,
3535
+ reseedFromRegistry: () => reseedFromRegistry,
3419
3536
  seedFromRegistry: () => seedFromRegistry,
3420
3537
  serializeReplayResult: () => serializeReplayResult
3421
3538
  });
@@ -4550,24 +4667,239 @@ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
4550
4667
  `opt-in and opt-out tracing can't be mixed in one call stack: ${enteredApi} (${entered})${subject} was entered inside a ${SURFACE_API[enclosing]} call (${enclosing}). ${MIXED_SURFACE_REMEDY[entered]}`
4551
4668
  );
4552
4669
  }
4553
- function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
4670
+ function assertSurfacesCompatible(requested, resolved2, parentSurface, traceFunctionKey) {
4554
4671
  if (requested === "inherit" || requested === "neutral") {
4555
4672
  return;
4556
4673
  }
4557
- if (resolved === void 0 || parentSurface === void 0) {
4674
+ if (resolved2 === void 0 || parentSurface === void 0) {
4558
4675
  return;
4559
4676
  }
4560
- if (parentSurface === resolved) {
4677
+ if (parentSurface === resolved2) {
4561
4678
  return;
4562
4679
  }
4563
4680
  throw mixedTracingError(
4564
- SURFACE_API[resolved],
4565
- resolved,
4681
+ SURFACE_API[resolved2],
4682
+ resolved2,
4566
4683
  parentSurface,
4567
4684
  traceFunctionKey
4568
4685
  );
4569
4686
  }
4570
4687
 
4688
+ // src/commitRef.ts
4689
+ init_gitCommand();
4690
+ init_readEnv();
4691
+ var EXPLICIT_SHA_ENV = "BITFAB_COMMIT_SHA";
4692
+ var DISABLE_ENV = "BITFAB_DISABLE_COMMIT_REF";
4693
+ var GIT_TIMEOUT_MS = 2e3;
4694
+ var GIT_MAX_BUFFER = 1024 * 1024;
4695
+ var VERCEL_PROVIDER_HOSTS = {
4696
+ github: "github.com",
4697
+ gitlab: "gitlab.com",
4698
+ bitbucket: "bitbucket.org"
4699
+ };
4700
+ function read(env, name) {
4701
+ if (name === null) {
4702
+ return null;
4703
+ }
4704
+ const value = env(name)?.trim();
4705
+ return value ? value : null;
4706
+ }
4707
+ function remoteFrom(...names) {
4708
+ return (env) => {
4709
+ const parts = names.map((name) => read(env, name));
4710
+ if (parts.some((part) => part === null)) {
4711
+ return null;
4712
+ }
4713
+ return normalizeRemote(parts.join("/"));
4714
+ };
4715
+ }
4716
+ function vercelRemote(env) {
4717
+ const provider = read(env, "VERCEL_GIT_PROVIDER")?.toLowerCase() ?? "";
4718
+ const host = VERCEL_PROVIDER_HOSTS[provider];
4719
+ const owner = read(env, "VERCEL_GIT_REPO_OWNER");
4720
+ const slug = read(env, "VERCEL_GIT_REPO_SLUG");
4721
+ if (!host || !owner || !slug) {
4722
+ return null;
4723
+ }
4724
+ return `${host}/${owner}/${slug}`;
4725
+ }
4726
+ function noRemote() {
4727
+ return null;
4728
+ }
4729
+ var PLATFORM_ENVS = [
4730
+ ["VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF", vercelRemote],
4731
+ [
4732
+ "GITHUB_SHA",
4733
+ "GITHUB_REF_NAME",
4734
+ remoteFrom("GITHUB_SERVER_URL", "GITHUB_REPOSITORY")
4735
+ ],
4736
+ ["RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH", noRemote],
4737
+ ["RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH", noRemote],
4738
+ ["SOURCE_VERSION", null, noRemote],
4739
+ ["CF_PAGES_COMMIT_SHA", "CF_PAGES_BRANCH", noRemote],
4740
+ ["CI_COMMIT_SHA", "CI_COMMIT_REF_NAME", remoteFrom("CI_REPOSITORY_URL")],
4741
+ [
4742
+ "BUILD_SOURCEVERSION",
4743
+ "BUILD_SOURCEBRANCHNAME",
4744
+ remoteFrom("BUILD_REPOSITORY_URI")
4745
+ ],
4746
+ ["CIRCLE_SHA1", "CIRCLE_BRANCH", remoteFrom("CIRCLE_REPOSITORY_URL")]
4747
+ ];
4748
+ var COMMIT_REF_ENV_NAMES = [
4749
+ EXPLICIT_SHA_ENV,
4750
+ DISABLE_ENV,
4751
+ ...PLATFORM_ENVS.flatMap(
4752
+ ([sha, branch]) => branch === null ? [sha] : [sha, branch]
4753
+ ),
4754
+ "GITHUB_SERVER_URL",
4755
+ "GITHUB_REPOSITORY",
4756
+ "CI_REPOSITORY_URL",
4757
+ "BUILD_REPOSITORY_URI",
4758
+ "CIRCLE_REPOSITORY_URL",
4759
+ "VERCEL_GIT_PROVIDER",
4760
+ "VERCEL_GIT_REPO_OWNER",
4761
+ "VERCEL_GIT_REPO_SLUG"
4762
+ ];
4763
+ function normalizeRemote(raw) {
4764
+ const value = raw?.trim();
4765
+ if (!value) {
4766
+ return null;
4767
+ }
4768
+ let host = "";
4769
+ let path = value;
4770
+ if (value.includes("://")) {
4771
+ try {
4772
+ const parsed = new URL(value);
4773
+ host = parsed.hostname;
4774
+ path = parsed.pathname;
4775
+ } catch {
4776
+ return null;
4777
+ }
4778
+ } else {
4779
+ const separator = value.indexOf(":");
4780
+ if (separator !== -1) {
4781
+ const head = value.slice(0, separator);
4782
+ host = head.slice(head.lastIndexOf("@") + 1);
4783
+ path = value.slice(separator + 1);
4784
+ }
4785
+ }
4786
+ path = path.replace(/^\/+|\/+$/g, "");
4787
+ if (path.endsWith(".git")) {
4788
+ path = path.slice(0, -".git".length).replace(/\/+$/, "");
4789
+ }
4790
+ if (!host) {
4791
+ return path || null;
4792
+ }
4793
+ return path ? `${host}/${path}` : host;
4794
+ }
4795
+ function resolveCommitRefFromEnv(env) {
4796
+ const explicit = read(env, EXPLICIT_SHA_ENV);
4797
+ const platform = PLATFORM_ENVS.find(([sha]) => read(env, sha) !== null);
4798
+ if (!platform) {
4799
+ if (explicit === null) {
4800
+ return null;
4801
+ }
4802
+ return {
4803
+ sha: explicit,
4804
+ branch: null,
4805
+ dirty: null,
4806
+ remote: null,
4807
+ rootSha: null
4808
+ };
4809
+ }
4810
+ const [shaEnv, branchEnv, readRemote] = platform;
4811
+ return {
4812
+ sha: explicit ?? read(env, shaEnv),
4813
+ branch: read(env, branchEnv),
4814
+ dirty: null,
4815
+ remote: readRemote(env),
4816
+ rootSha: null
4817
+ };
4818
+ }
4819
+ async function resolveCommitRefFromGit(cwd) {
4820
+ const git = await gitRunner({
4821
+ timeoutMs: GIT_TIMEOUT_MS,
4822
+ maxBuffer: GIT_MAX_BUFFER,
4823
+ keepProcessAlive: false
4824
+ });
4825
+ if (!git) {
4826
+ return null;
4827
+ }
4828
+ const run = async (args) => (await git(cwd, args))?.trim() ?? null;
4829
+ const sha = await run(["rev-parse", "HEAD"]);
4830
+ if (!sha) {
4831
+ return null;
4832
+ }
4833
+ const [branch, status, remote, roots] = await Promise.all([
4834
+ run(["symbolic-ref", "--short", "-q", "HEAD"]),
4835
+ run(["status", "--porcelain"]),
4836
+ run(["remote", "get-url", "origin"]),
4837
+ run(["rev-list", "--max-parents=0", "HEAD"])
4838
+ ]);
4839
+ return {
4840
+ sha,
4841
+ branch: branch || null,
4842
+ dirty: status === null ? null : status.length > 0,
4843
+ remote: normalizeRemote(remote),
4844
+ rootSha: roots ? roots.split(/\s+/).sort()[0] ?? null : null
4845
+ };
4846
+ }
4847
+ function commitRefWire(ref2) {
4848
+ return {
4849
+ sha: ref2.sha,
4850
+ branch: ref2.branch,
4851
+ dirty: ref2.dirty,
4852
+ remote: ref2.remote,
4853
+ root_sha: ref2.rootSha
4854
+ };
4855
+ }
4856
+ var resolved = false;
4857
+ var ref = null;
4858
+ var gitStarted = false;
4859
+ var settled = Promise.resolve();
4860
+ function startCommitRefResolution() {
4861
+ if (resolved || gitStarted) {
4862
+ return;
4863
+ }
4864
+ if (read(readEnv, DISABLE_ENV) !== null) {
4865
+ resolved = true;
4866
+ return;
4867
+ }
4868
+ const fromEnv = resolveCommitRefFromEnv(readEnv);
4869
+ if (fromEnv) {
4870
+ ref = fromEnv;
4871
+ resolved = true;
4872
+ return;
4873
+ }
4874
+ gitStarted = true;
4875
+ if (typeof process === "undefined") {
4876
+ resolved = true;
4877
+ return;
4878
+ }
4879
+ let cwd;
4880
+ try {
4881
+ cwd = process.cwd?.() ?? ".";
4882
+ } catch {
4883
+ resolved = true;
4884
+ return;
4885
+ }
4886
+ settled = resolveCommitRefFromGit(cwd).then(
4887
+ (fromGit) => {
4888
+ if (!resolved) {
4889
+ ref = fromGit;
4890
+ resolved = true;
4891
+ }
4892
+ },
4893
+ () => {
4894
+ resolved = true;
4895
+ }
4896
+ );
4897
+ }
4898
+ function currentCommitRef() {
4899
+ startCommitRefResolution();
4900
+ return ref;
4901
+ }
4902
+
4571
4903
  // src/client.ts
4572
4904
  init_constants();
4573
4905
 
@@ -5060,11 +5392,11 @@ var BitfabLangGraphCallbackHandler = class {
5060
5392
  this.invocations.set(invocation.rootRunId, invocation);
5061
5393
  }
5062
5394
  if (!willHide) {
5063
- let resolved = parentSpan;
5064
- while (resolved?.hidden === true) {
5065
- resolved = resolved.parentId ? this.runToSpan.get(resolved.parentId) : void 0;
5395
+ let resolved2 = parentSpan;
5396
+ while (resolved2?.hidden === true) {
5397
+ resolved2 = resolved2.parentId ? this.runToSpan.get(resolved2.parentId) : void 0;
5066
5398
  }
5067
- effectiveParentId = resolved ? resolved.spanId : invocation.activeContext?.spanId ?? null;
5399
+ effectiveParentId = resolved2 ? resolved2.spanId : invocation.activeContext?.spanId ?? null;
5068
5400
  } else {
5069
5401
  effectiveParentId = parentRunId ?? null;
5070
5402
  }
@@ -5732,6 +6064,7 @@ var BitfabOpenAIAgentHandler = class {
5732
6064
 
5733
6065
  // src/client.ts
5734
6066
  init_randomUuid();
6067
+ init_replay();
5735
6068
 
5736
6069
  // src/replayBranch.ts
5737
6070
  var _url, _context;
@@ -6563,6 +6896,7 @@ var Bitfab = class {
6563
6896
  validateDbSnapshotConfig(config.dbSnapshot);
6564
6897
  }
6565
6898
  this.dbSnapshot = config.dbSnapshot;
6899
+ startCommitRefResolution();
6566
6900
  this.httpClient = new HttpClient({
6567
6901
  apiKey: () => this.resolveApiKey(),
6568
6902
  serviceUrl: this.serviceUrl,
@@ -7656,15 +7990,15 @@ var Bitfab = class {
7656
7990
  );
7657
7991
  }
7658
7992
  return runWithSpanStack(newStack, async () => {
7659
- const resolved = await resolution;
7660
- if (resolved.matched) {
7993
+ const resolved2 = await resolution;
7994
+ if (resolved2.matched) {
7661
7995
  void sendSpan({
7662
- result: resolved.output,
7996
+ result: resolved2.output,
7663
7997
  mocked: true,
7664
7998
  mockTarget: "output",
7665
7999
  mockSource: "override"
7666
8000
  });
7667
- return resolved.output;
8001
+ return resolved2.output;
7668
8002
  }
7669
8003
  if (shouldMockWithBaseStrategy && !mockSpan) {
7670
8004
  throw new BitfabError(
@@ -7900,6 +8234,10 @@ var Bitfab = class {
7900
8234
  if (params.dbSnapshotRef) {
7901
8235
  rawTrace.db_snapshot_ref = params.dbSnapshotRef;
7902
8236
  }
8237
+ const commitRef = currentCommitRef();
8238
+ if (commitRef) {
8239
+ rawTrace.commit_ref = commitRefWire(commitRef);
8240
+ }
7903
8241
  if (params.ingestionType) {
7904
8242
  rawTrace.ingestion_type = params.ingestionType;
7905
8243
  }
@@ -8159,6 +8497,36 @@ var Bitfab = class {
8159
8497
  }
8160
8498
  return traceId;
8161
8499
  }
8500
+ async reseedTrace(traceFunctionKey, fn, options) {
8501
+ const source = await this.httpClient.getReseedSource(options.traceId);
8502
+ if (source.traceFunctionKey !== traceFunctionKey) {
8503
+ throw new BitfabError(
8504
+ `Trace ${options.traceId} belongs to '${source.traceFunctionKey}', not '${traceFunctionKey}'.`
8505
+ );
8506
+ }
8507
+ const args = deserializeInputs({
8508
+ input: source.input,
8509
+ input_meta: source.inputMeta
8510
+ });
8511
+ const runTraceId = await this.seedTraceByRunning(
8512
+ traceFunctionKey,
8513
+ fn,
8514
+ {
8515
+ args,
8516
+ metadata: source.metadata,
8517
+ ...source.sessionId === null ? {} : { sessionId: source.sessionId },
8518
+ ...source.name === null ? {} : { name: source.name }
8519
+ }
8520
+ );
8521
+ const adopted = await this.httpClient.reseedTrace(
8522
+ options.traceId,
8523
+ runTraceId
8524
+ );
8525
+ return {
8526
+ traceId: adopted.traceId,
8527
+ previousRunTraceId: adopted.previousRunTraceId
8528
+ };
8529
+ }
8162
8530
  async replay(traceFunctionKey, fn, options) {
8163
8531
  const wrappedKey = fn._bitfabTraceFunctionKey;
8164
8532
  let replayFn = fn;
@@ -8420,6 +8788,24 @@ init_replay();
8420
8788
  function defineReplayRegistry(registry) {
8421
8789
  return registry;
8422
8790
  }
8791
+ async function reseedFromRegistry(registry, pipeline, traceIds) {
8792
+ const registration = registry[pipeline];
8793
+ if (registration === void 0) {
8794
+ throw new BitfabError(
8795
+ `Unknown pipeline '${pipeline}'. Registered: ${Object.keys(registry).join(", ")}`
8796
+ );
8797
+ }
8798
+ const traceFunctionKey = resolveTraceFunctionKey(registration);
8799
+ const reseeded = [];
8800
+ for (const traceId of traceIds) {
8801
+ reseeded.push(
8802
+ await registration.client.reseedTrace(traceFunctionKey, registration.fn, {
8803
+ traceId
8804
+ })
8805
+ );
8806
+ }
8807
+ return { pipeline, traceFunctionKey, reseeded };
8808
+ }
8423
8809
  async function seedFromRegistry(registry, pipeline, cases, options = {}) {
8424
8810
  const registration = registry[pipeline];
8425
8811
  if (registration === void 0) {
@@ -8500,6 +8886,7 @@ assertAsyncStorageRegistered();
8500
8886
  getCurrentSpan,
8501
8887
  getCurrentTrace,
8502
8888
  reportReplayProgress,
8889
+ reseedFromRegistry,
8503
8890
  seedFromRegistry,
8504
8891
  serializeReplayResult
8505
8892
  });