@probelabs/probe 0.6.0-rc142 → 0.6.0-rc144

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.
@@ -27268,6 +27268,145 @@ var init_directory_resolver = __esm({
27268
27268
  });
27269
27269
 
27270
27270
  // src/downloader.js
27271
+ async function acquireFileLock(lockPath, version) {
27272
+ const lockData = {
27273
+ version,
27274
+ pid: process.pid,
27275
+ timestamp: Date.now()
27276
+ };
27277
+ try {
27278
+ await import_fs_extra2.default.writeFile(lockPath, JSON.stringify(lockData), { flag: "wx" });
27279
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27280
+ console.log(`Acquired file lock: ${lockPath}`);
27281
+ }
27282
+ return true;
27283
+ } catch (error2) {
27284
+ if (error2.code === "EEXIST") {
27285
+ try {
27286
+ const existingLock = JSON.parse(await import_fs_extra2.default.readFile(lockPath, "utf-8"));
27287
+ const lockAge = Date.now() - existingLock.timestamp;
27288
+ if (lockAge > LOCK_TIMEOUT_MS) {
27289
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27290
+ console.log(`Removing stale lock file (age: ${Math.round(lockAge / 1e3)}s, pid: ${existingLock.pid})`);
27291
+ }
27292
+ await import_fs_extra2.default.remove(lockPath);
27293
+ return false;
27294
+ }
27295
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27296
+ console.log(`Download in progress by process ${existingLock.pid}, waiting...`);
27297
+ }
27298
+ return false;
27299
+ } catch (readError) {
27300
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27301
+ console.log(`Lock file corrupted, removing: ${readError.message}`);
27302
+ }
27303
+ try {
27304
+ await import_fs_extra2.default.remove(lockPath);
27305
+ } catch {
27306
+ }
27307
+ return false;
27308
+ }
27309
+ }
27310
+ if (error2.code === "EACCES" || error2.code === "EPERM" || error2.code === "EROFS") {
27311
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27312
+ console.log(`Cannot create lock file (${error2.code}): ${lockPath}`);
27313
+ console.log(`File-based locking unavailable, will proceed without cross-process coordination`);
27314
+ }
27315
+ return null;
27316
+ }
27317
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27318
+ console.log(`Unexpected error creating lock file: ${error2.message}`);
27319
+ console.log(`Proceeding without file-based lock`);
27320
+ }
27321
+ return null;
27322
+ }
27323
+ }
27324
+ async function releaseFileLock(lockPath) {
27325
+ try {
27326
+ await import_fs_extra2.default.remove(lockPath);
27327
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27328
+ console.log(`Released file lock: ${lockPath}`);
27329
+ }
27330
+ } catch (error2) {
27331
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27332
+ console.log(`Warning: Could not release lock file: ${error2.message}`);
27333
+ }
27334
+ }
27335
+ }
27336
+ async function waitForFileLock(lockPath, binaryPath) {
27337
+ const startTime = Date.now();
27338
+ while (Date.now() - startTime < MAX_LOCK_WAIT_MS) {
27339
+ if (await import_fs_extra2.default.pathExists(binaryPath)) {
27340
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27341
+ console.log(`Binary now available at ${binaryPath}, download completed by another process`);
27342
+ }
27343
+ return true;
27344
+ }
27345
+ const lockExists = await import_fs_extra2.default.pathExists(lockPath);
27346
+ if (!lockExists) {
27347
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27348
+ console.log(`Lock file removed but binary not found - download may have failed`);
27349
+ }
27350
+ return false;
27351
+ }
27352
+ try {
27353
+ const lockData = JSON.parse(await import_fs_extra2.default.readFile(lockPath, "utf-8"));
27354
+ const lockAge = Date.now() - lockData.timestamp;
27355
+ if (lockAge > LOCK_TIMEOUT_MS) {
27356
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27357
+ console.log(`Lock expired (age: ${Math.round(lockAge / 1e3)}s), will retry download`);
27358
+ }
27359
+ return false;
27360
+ }
27361
+ } catch {
27362
+ }
27363
+ await new Promise((resolve4) => setTimeout(resolve4, LOCK_POLL_INTERVAL_MS));
27364
+ }
27365
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27366
+ console.log(`Timeout waiting for file lock`);
27367
+ }
27368
+ return false;
27369
+ }
27370
+ async function withDownloadLock(version, downloadFn) {
27371
+ const lockKey = version || "latest";
27372
+ if (downloadLocks.has(lockKey)) {
27373
+ const lock = downloadLocks.get(lockKey);
27374
+ const lockAge = Date.now() - lock.timestamp;
27375
+ if (lockAge > LOCK_TIMEOUT_MS) {
27376
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27377
+ console.log(`In-memory lock for version ${lockKey} expired (age: ${Math.round(lockAge / 1e3)}s), removing stale lock`);
27378
+ }
27379
+ downloadLocks.delete(lockKey);
27380
+ } else {
27381
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27382
+ console.log(`Download already in progress in this process for version ${lockKey}, waiting...`);
27383
+ }
27384
+ try {
27385
+ return await lock.promise;
27386
+ } catch (error2) {
27387
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27388
+ console.log(`In-memory locked download failed, will retry: ${error2.message}`);
27389
+ }
27390
+ }
27391
+ }
27392
+ }
27393
+ const downloadPromise = Promise.race([
27394
+ downloadFn(),
27395
+ new Promise(
27396
+ (_2, reject2) => setTimeout(() => reject2(new Error(`Download timeout after ${LOCK_TIMEOUT_MS / 1e3}s`)), LOCK_TIMEOUT_MS)
27397
+ )
27398
+ ]);
27399
+ downloadLocks.set(lockKey, {
27400
+ promise: downloadPromise,
27401
+ timestamp: Date.now()
27402
+ });
27403
+ try {
27404
+ const result = await downloadPromise;
27405
+ return result;
27406
+ } finally {
27407
+ downloadLocks.delete(lockKey);
27408
+ }
27409
+ }
27271
27410
  function detectOsArch() {
27272
27411
  const osType = import_os2.default.platform();
27273
27412
  const archType = import_os2.default.arch();
@@ -27711,16 +27850,64 @@ async function getPackageVersion() {
27711
27850
  return "0.0.0";
27712
27851
  }
27713
27852
  }
27853
+ async function doDownload(version) {
27854
+ const localDir = await getPackageBinDir();
27855
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27856
+ console.log(`Downloading probe binary (version: ${version || "latest"})...`);
27857
+ console.log(`Using binary directory: ${localDir}`);
27858
+ }
27859
+ const isWindows = import_os2.default.platform() === "win32";
27860
+ const binaryName = isWindows ? `${BINARY_NAME}.exe` : `${BINARY_NAME}-binary`;
27861
+ const binaryPath = import_path2.default.join(localDir, binaryName);
27862
+ const { os: osInfo, arch: archInfo } = detectOsArch();
27863
+ let versionToUse = version;
27864
+ let bestAsset;
27865
+ let tagVersion;
27866
+ if (!versionToUse || versionToUse === "0.0.0") {
27867
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27868
+ console.log("No specific version requested, will use the latest release");
27869
+ }
27870
+ const { tag: tag2, assets } = await getLatestRelease(void 0);
27871
+ tagVersion = tag2.startsWith("v") ? tag2.substring(1) : tag2;
27872
+ bestAsset = findBestAsset(assets, osInfo, archInfo);
27873
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27874
+ console.log(`Found release version: ${tagVersion}`);
27875
+ }
27876
+ } else {
27877
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27878
+ console.log(`Direct download for version: ${versionToUse}`);
27879
+ }
27880
+ tagVersion = versionToUse;
27881
+ bestAsset = constructAssetInfo(versionToUse, osInfo, archInfo);
27882
+ }
27883
+ const { assetPath, checksumPath } = await downloadAsset(bestAsset, localDir);
27884
+ const checksumValid = await verifyChecksum(assetPath, checksumPath);
27885
+ if (!checksumValid) {
27886
+ throw new Error("Checksum verification failed");
27887
+ }
27888
+ const extractedBinaryPath = await extractBinary(assetPath, localDir);
27889
+ await saveVersionInfo(tagVersion, localDir);
27890
+ try {
27891
+ await import_fs_extra2.default.remove(assetPath);
27892
+ if (checksumPath) {
27893
+ await import_fs_extra2.default.remove(checksumPath);
27894
+ }
27895
+ } catch (err) {
27896
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27897
+ console.log(`Warning: Could not clean up temporary files: ${err}`);
27898
+ }
27899
+ }
27900
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27901
+ console.log(`Binary successfully installed at ${extractedBinaryPath} (version: ${tagVersion})`);
27902
+ }
27903
+ return extractedBinaryPath;
27904
+ }
27714
27905
  async function downloadProbeBinary(version) {
27715
27906
  try {
27716
27907
  const localDir = await getPackageBinDir();
27717
27908
  if (!version || version === "0.0.0") {
27718
27909
  version = await getPackageVersion();
27719
27910
  }
27720
- if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27721
- console.log(`Downloading probe binary (version: ${version || "latest"})...`);
27722
- console.log(`Using binary directory: ${localDir}`);
27723
- }
27724
27911
  const isWindows = import_os2.default.platform() === "win32";
27725
27912
  const binaryName = isWindows ? `${BINARY_NAME}.exe` : `${BINARY_NAME}-binary`;
27726
27913
  const binaryPath = import_path2.default.join(localDir, binaryName);
@@ -27736,54 +27923,44 @@ async function downloadProbeBinary(version) {
27736
27923
  console.log(`Existing binary version (${versionInfo?.version || "unknown"}) doesn't match requested version (${version}). Downloading new version...`);
27737
27924
  }
27738
27925
  }
27739
- const { os: osInfo, arch: archInfo } = detectOsArch();
27740
- let versionToUse = version;
27741
- let bestAsset;
27742
- let tagVersion;
27743
- if (!versionToUse || versionToUse === "0.0.0") {
27744
- if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27745
- console.log("No specific version requested, will use the latest release");
27746
- }
27747
- const { tag: tag2, assets } = await getLatestRelease(void 0);
27748
- tagVersion = tag2.startsWith("v") ? tag2.substring(1) : tag2;
27749
- bestAsset = findBestAsset(assets, osInfo, archInfo);
27750
- if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27751
- console.log(`Found release version: ${tagVersion}`);
27926
+ const lockPath = import_path2.default.join(localDir, `.probe-download-${version}.lock`);
27927
+ const maxRetries = 3;
27928
+ for (let retry = 0; retry < maxRetries; retry++) {
27929
+ const lockAcquired = await acquireFileLock(lockPath, version);
27930
+ if (lockAcquired === true) {
27931
+ try {
27932
+ const result = await withDownloadLock(version, () => doDownload(version));
27933
+ return result;
27934
+ } finally {
27935
+ await releaseFileLock(lockPath);
27936
+ }
27752
27937
  }
27753
- } else {
27754
- if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27755
- console.log(`Direct download for version: ${versionToUse}`);
27938
+ if (lockAcquired === null) {
27939
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27940
+ console.log(`File-based locking unavailable, downloading without cross-process coordination`);
27941
+ }
27942
+ return await withDownloadLock(version, () => doDownload(version));
27756
27943
  }
27757
- tagVersion = versionToUse;
27758
- bestAsset = constructAssetInfo(versionToUse, osInfo, archInfo);
27759
- }
27760
- const { assetPath, checksumPath } = await downloadAsset(bestAsset, localDir);
27761
- const checksumValid = await verifyChecksum(assetPath, checksumPath);
27762
- if (!checksumValid) {
27763
- throw new Error("Checksum verification failed");
27764
- }
27765
- const extractedBinaryPath = await extractBinary(assetPath, localDir);
27766
- await saveVersionInfo(tagVersion, localDir);
27767
- try {
27768
- await import_fs_extra2.default.remove(assetPath);
27769
- if (checksumPath) {
27770
- await import_fs_extra2.default.remove(checksumPath);
27944
+ const downloadCompleted = await waitForFileLock(lockPath, binaryPath);
27945
+ if (downloadCompleted) {
27946
+ return binaryPath;
27771
27947
  }
27772
- } catch (err) {
27773
- if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27774
- console.log(`Warning: Could not clean up temporary files: ${err}`);
27948
+ if (retry < maxRetries - 1) {
27949
+ if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27950
+ console.log(`Retrying download (attempt ${retry + 2}/${maxRetries})...`);
27951
+ }
27775
27952
  }
27776
27953
  }
27777
27954
  if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
27778
- console.log(`Binary successfully installed at ${extractedBinaryPath} (version: ${tagVersion})`);
27955
+ console.log(`All lock attempts exhausted, attempting direct download`);
27779
27956
  }
27780
- return extractedBinaryPath;
27957
+ return await withDownloadLock(version, () => doDownload(version));
27781
27958
  } catch (error2) {
27782
27959
  console.error("Error downloading probe binary:", error2);
27783
27960
  throw error2;
27784
27961
  }
27785
27962
  }
27786
- var import_axios, import_fs_extra2, import_path2, import_crypto, import_util3, import_child_process, import_tar, import_os2, import_url2, exec, REPO_OWNER, REPO_NAME, BINARY_NAME, __filename2, __dirname2;
27963
+ var import_axios, import_fs_extra2, import_path2, import_crypto, import_util3, import_child_process, import_tar, import_os2, import_url2, exec, REPO_OWNER, REPO_NAME, BINARY_NAME, __filename2, __dirname2, downloadLocks, LOCK_TIMEOUT_MS, LOCK_POLL_INTERVAL_MS, MAX_LOCK_WAIT_MS;
27787
27964
  var init_downloader = __esm({
27788
27965
  "src/downloader.js"() {
27789
27966
  "use strict";
@@ -27804,19 +27981,25 @@ var init_downloader = __esm({
27804
27981
  BINARY_NAME = "probe";
27805
27982
  __filename2 = (0, import_url2.fileURLToPath)("file:///");
27806
27983
  __dirname2 = import_path2.default.dirname(__filename2);
27984
+ downloadLocks = /* @__PURE__ */ new Map();
27985
+ LOCK_TIMEOUT_MS = 5 * 60 * 1e3;
27986
+ LOCK_POLL_INTERVAL_MS = 1e3;
27987
+ MAX_LOCK_WAIT_MS = 5 * 60 * 1e3;
27807
27988
  }
27808
27989
  });
27809
27990
 
27810
27991
  // src/utils.js
27811
27992
  async function getBinaryPath(options = {}) {
27812
27993
  const { forceDownload = false, version } = options;
27813
- if (probeBinaryPath && !forceDownload && import_fs_extra3.default.existsSync(probeBinaryPath)) {
27814
- return probeBinaryPath;
27815
- }
27816
27994
  if (process.env.PROBE_PATH && import_fs_extra3.default.existsSync(process.env.PROBE_PATH) && !forceDownload) {
27817
27995
  probeBinaryPath = process.env.PROBE_PATH;
27818
27996
  return probeBinaryPath;
27819
27997
  }
27998
+ if (version && !forceDownload) {
27999
+ console.log(`Specific version ${version} requested. Downloading...`);
28000
+ probeBinaryPath = await downloadProbeBinary(version);
28001
+ return probeBinaryPath;
28002
+ }
27820
28003
  const binDir = await getPackageBinDir();
27821
28004
  const isWindows = process.platform === "win32";
27822
28005
  const binaryName = isWindows ? "probe.exe" : "probe-binary";
@@ -32477,6 +32660,12 @@ function createMessagePreview(message, charsPerSide = 200) {
32477
32660
  const end = message.substring(message.length - charsPerSide);
32478
32661
  return `${start}...${end}`;
32479
32662
  }
32663
+ function parseTargets(targets) {
32664
+ if (!targets || typeof targets !== "string") {
32665
+ return [];
32666
+ }
32667
+ return targets.split(/\s+/).filter((f3) => f3.length > 0);
32668
+ }
32480
32669
  var searchSchema, querySchema, extractSchema, delegateSchema, bashSchema, attemptCompletionSchema, searchToolDefinition, queryToolDefinition, extractToolDefinition, attemptCompletionToolDefinition, searchDescription, queryDescription, extractDescription, delegateDescription, DEFAULT_VALID_TOOLS;
32481
32670
  var init_common2 = __esm({
32482
32671
  "src/tools/common.js"() {
@@ -33055,7 +33244,7 @@ var init_vercel = __esm({
33055
33244
  format: effectiveFormat
33056
33245
  };
33057
33246
  } else if (targets) {
33058
- const files = [targets];
33247
+ const files = parseTargets(targets);
33059
33248
  let effectiveFormat = format2;
33060
33249
  if (outline && format2 === "outline-xml") {
33061
33250
  effectiveFormat = "xml";