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.cjs CHANGED
@@ -659,6 +659,7 @@ __export(index_exports, {
659
659
  module.exports = __toCommonJS(index_exports);
660
660
  var import_fs5 = require("fs");
661
661
  var path7 = __toESM(require("path"), 1);
662
+ var os3 = __toESM(require("os"), 1);
662
663
 
663
664
  // src/config/schema.ts
664
665
  var DEFAULT_INCLUDE = [
@@ -2811,6 +2812,22 @@ function float32ArrayToBuffer(arr) {
2811
2812
  function bufferToFloat32Array(buf) {
2812
2813
  return new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
2813
2814
  }
2815
+ function getErrorMessage(error) {
2816
+ if (error instanceof Error) {
2817
+ return error.message;
2818
+ }
2819
+ if (typeof error === "string") {
2820
+ return error;
2821
+ }
2822
+ if (error && typeof error === "object" && "message" in error) {
2823
+ return String(error.message);
2824
+ }
2825
+ return String(error);
2826
+ }
2827
+ function isRateLimitError(error) {
2828
+ const message = getErrorMessage(error);
2829
+ return message.includes("429") || message.toLowerCase().includes("rate limit") || message.toLowerCase().includes("too many requests");
2830
+ }
2814
2831
  var Indexer = class {
2815
2832
  config;
2816
2833
  projectRoot;
@@ -3168,10 +3185,20 @@ var Indexer = class {
3168
3185
  {
3169
3186
  retries: this.config.indexing.retries,
3170
3187
  minTimeout: this.config.indexing.retryDelayMs,
3188
+ maxTimeout: 3e4,
3189
+ factor: 2,
3171
3190
  onFailedAttempt: (error) => {
3172
- console.error(
3173
- `Embedding batch failed (attempt ${error.attemptNumber}): ${String(error)}`
3174
- );
3191
+ const message = getErrorMessage(error);
3192
+ if (isRateLimitError(error)) {
3193
+ queue.concurrency = 1;
3194
+ console.error(
3195
+ `Rate limited (attempt ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber}): waiting before retry...`
3196
+ );
3197
+ } else {
3198
+ console.error(
3199
+ `Embedding batch failed (attempt ${error.attemptNumber}): ${message}`
3200
+ );
3201
+ }
3175
3202
  }
3176
3203
  }
3177
3204
  );
@@ -3204,8 +3231,8 @@ var Indexer = class {
3204
3231
  });
3205
3232
  } catch (error) {
3206
3233
  stats.failedChunks += batch.length;
3207
- this.addFailedBatch(batch, String(error));
3208
- console.error(`Failed to embed batch after retries: ${error}`);
3234
+ this.addFailedBatch(batch, getErrorMessage(error));
3235
+ console.error(`Failed to embed batch after retries: ${getErrorMessage(error)}`);
3209
3236
  }
3210
3237
  });
3211
3238
  }
@@ -5556,15 +5583,26 @@ function formatStatus(status) {
5556
5583
  }
5557
5584
 
5558
5585
  // src/index.ts
5559
- function loadPluginConfig(projectRoot) {
5560
- const configPath = path7.join(projectRoot, ".opencode", "codebase-index.json");
5586
+ function loadJsonFile(filePath) {
5561
5587
  try {
5562
- if ((0, import_fs5.existsSync)(configPath)) {
5563
- const content = (0, import_fs5.readFileSync)(configPath, "utf-8");
5588
+ if ((0, import_fs5.existsSync)(filePath)) {
5589
+ const content = (0, import_fs5.readFileSync)(filePath, "utf-8");
5564
5590
  return JSON.parse(content);
5565
5591
  }
5566
5592
  } catch {
5567
5593
  }
5594
+ return null;
5595
+ }
5596
+ function loadPluginConfig(projectRoot) {
5597
+ const projectConfig = loadJsonFile(path7.join(projectRoot, ".opencode", "codebase-index.json"));
5598
+ if (projectConfig) {
5599
+ return projectConfig;
5600
+ }
5601
+ const globalConfigPath = path7.join(os3.homedir(), ".config", "opencode", "codebase-index.json");
5602
+ const globalConfig = loadJsonFile(globalConfigPath);
5603
+ if (globalConfig) {
5604
+ return globalConfig;
5605
+ }
5568
5606
  return {};
5569
5607
  }
5570
5608
  var plugin = async ({ directory }) => {