opencode-codebase-index 0.2.2 → 0.2.4

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 = [
@@ -3171,10 +3172,14 @@ var Indexer = class {
3171
3172
  stats.indexedChunks++;
3172
3173
  }
3173
3174
  }
3174
- const queue = new PQueue({ concurrency: 3 });
3175
+ const queue = new PQueue({ concurrency: 1, interval: 4e3, intervalCap: 1 });
3175
3176
  const dynamicBatches = createDynamicBatches(chunksNeedingEmbedding);
3177
+ let rateLimitBackoffMs = 0;
3176
3178
  for (const batch of dynamicBatches) {
3177
3179
  queue.add(async () => {
3180
+ if (rateLimitBackoffMs > 0) {
3181
+ await new Promise((resolve4) => setTimeout(resolve4, rateLimitBackoffMs));
3182
+ }
3178
3183
  try {
3179
3184
  const result = await pRetry(
3180
3185
  async () => {
@@ -3183,15 +3188,17 @@ var Indexer = class {
3183
3188
  },
3184
3189
  {
3185
3190
  retries: this.config.indexing.retries,
3186
- minTimeout: this.config.indexing.retryDelayMs,
3187
- maxTimeout: 3e4,
3191
+ minTimeout: Math.max(this.config.indexing.retryDelayMs, 5e3),
3192
+ // Minimum 5s between retries
3193
+ maxTimeout: 6e4,
3194
+ // Max 60s backoff
3188
3195
  factor: 2,
3189
3196
  onFailedAttempt: (error) => {
3190
3197
  const message = getErrorMessage(error);
3191
3198
  if (isRateLimitError(error)) {
3192
- queue.concurrency = 1;
3199
+ rateLimitBackoffMs = Math.min(6e4, (rateLimitBackoffMs || 5e3) * 2);
3193
3200
  console.error(
3194
- `Rate limited (attempt ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber}): waiting before retry...`
3201
+ `Rate limited (attempt ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber}): waiting ${rateLimitBackoffMs / 1e3}s before retry...`
3195
3202
  );
3196
3203
  } else {
3197
3204
  console.error(
@@ -3201,6 +3208,9 @@ var Indexer = class {
3201
3208
  }
3202
3209
  }
3203
3210
  );
3211
+ if (rateLimitBackoffMs > 0) {
3212
+ rateLimitBackoffMs = Math.max(0, rateLimitBackoffMs - 2e3);
3213
+ }
3204
3214
  const items = batch.map((chunk, idx) => ({
3205
3215
  id: chunk.id,
3206
3216
  vector: result.embeddings[idx],
@@ -5582,15 +5592,26 @@ function formatStatus(status) {
5582
5592
  }
5583
5593
 
5584
5594
  // src/index.ts
5585
- function loadPluginConfig(projectRoot) {
5586
- const configPath = path7.join(projectRoot, ".opencode", "codebase-index.json");
5595
+ function loadJsonFile(filePath) {
5587
5596
  try {
5588
- if ((0, import_fs5.existsSync)(configPath)) {
5589
- const content = (0, import_fs5.readFileSync)(configPath, "utf-8");
5597
+ if ((0, import_fs5.existsSync)(filePath)) {
5598
+ const content = (0, import_fs5.readFileSync)(filePath, "utf-8");
5590
5599
  return JSON.parse(content);
5591
5600
  }
5592
5601
  } catch {
5593
5602
  }
5603
+ return null;
5604
+ }
5605
+ function loadPluginConfig(projectRoot) {
5606
+ const projectConfig = loadJsonFile(path7.join(projectRoot, ".opencode", "codebase-index.json"));
5607
+ if (projectConfig) {
5608
+ return projectConfig;
5609
+ }
5610
+ const globalConfigPath = path7.join(os3.homedir(), ".config", "opencode", "codebase-index.json");
5611
+ const globalConfig = loadJsonFile(globalConfigPath);
5612
+ if (globalConfig) {
5613
+ return globalConfig;
5614
+ }
5594
5615
  return {};
5595
5616
  }
5596
5617
  var plugin = async ({ directory }) => {