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