opencode-codebase-index 0.2.1 → 0.2.3

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.
package/dist/index.js CHANGED
@@ -654,6 +654,7 @@ var require_ignore = __commonJS({
654
654
  // src/index.ts
655
655
  import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
656
656
  import * as path7 from "path";
657
+ import * as os3 from "os";
657
658
 
658
659
  // src/config/schema.ts
659
660
  var DEFAULT_INCLUDE = [
@@ -2805,6 +2806,22 @@ function float32ArrayToBuffer(arr) {
2805
2806
  function bufferToFloat32Array(buf) {
2806
2807
  return new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
2807
2808
  }
2809
+ function getErrorMessage(error) {
2810
+ if (error instanceof Error) {
2811
+ return error.message;
2812
+ }
2813
+ if (typeof error === "string") {
2814
+ return error;
2815
+ }
2816
+ if (error && typeof error === "object" && "message" in error) {
2817
+ return String(error.message);
2818
+ }
2819
+ return String(error);
2820
+ }
2821
+ function isRateLimitError(error) {
2822
+ const message = getErrorMessage(error);
2823
+ return message.includes("429") || message.toLowerCase().includes("rate limit") || message.toLowerCase().includes("too many requests");
2824
+ }
2808
2825
  var Indexer = class {
2809
2826
  config;
2810
2827
  projectRoot;
@@ -3162,10 +3179,20 @@ var Indexer = class {
3162
3179
  {
3163
3180
  retries: this.config.indexing.retries,
3164
3181
  minTimeout: this.config.indexing.retryDelayMs,
3182
+ maxTimeout: 3e4,
3183
+ factor: 2,
3165
3184
  onFailedAttempt: (error) => {
3166
- console.error(
3167
- `Embedding batch failed (attempt ${error.attemptNumber}): ${String(error)}`
3168
- );
3185
+ const message = getErrorMessage(error);
3186
+ if (isRateLimitError(error)) {
3187
+ queue.concurrency = 1;
3188
+ console.error(
3189
+ `Rate limited (attempt ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber}): waiting before retry...`
3190
+ );
3191
+ } else {
3192
+ console.error(
3193
+ `Embedding batch failed (attempt ${error.attemptNumber}): ${message}`
3194
+ );
3195
+ }
3169
3196
  }
3170
3197
  }
3171
3198
  );
@@ -3198,8 +3225,8 @@ var Indexer = class {
3198
3225
  });
3199
3226
  } catch (error) {
3200
3227
  stats.failedChunks += batch.length;
3201
- this.addFailedBatch(batch, String(error));
3202
- console.error(`Failed to embed batch after retries: ${error}`);
3228
+ this.addFailedBatch(batch, getErrorMessage(error));
3229
+ console.error(`Failed to embed batch after retries: ${getErrorMessage(error)}`);
3203
3230
  }
3204
3231
  });
3205
3232
  }
@@ -5550,15 +5577,26 @@ function formatStatus(status) {
5550
5577
  }
5551
5578
 
5552
5579
  // src/index.ts
5553
- function loadPluginConfig(projectRoot) {
5554
- const configPath = path7.join(projectRoot, ".opencode", "codebase-index.json");
5580
+ function loadJsonFile(filePath) {
5555
5581
  try {
5556
- if (existsSync5(configPath)) {
5557
- const content = readFileSync5(configPath, "utf-8");
5582
+ if (existsSync5(filePath)) {
5583
+ const content = readFileSync5(filePath, "utf-8");
5558
5584
  return JSON.parse(content);
5559
5585
  }
5560
5586
  } catch {
5561
5587
  }
5588
+ return null;
5589
+ }
5590
+ function loadPluginConfig(projectRoot) {
5591
+ const projectConfig = loadJsonFile(path7.join(projectRoot, ".opencode", "codebase-index.json"));
5592
+ if (projectConfig) {
5593
+ return projectConfig;
5594
+ }
5595
+ const globalConfigPath = path7.join(os3.homedir(), ".config", "opencode", "codebase-index.json");
5596
+ const globalConfig = loadJsonFile(globalConfigPath);
5597
+ if (globalConfig) {
5598
+ return globalConfig;
5599
+ }
5562
5600
  return {};
5563
5601
  }
5564
5602
  var plugin = async ({ directory }) => {