opencode-rag-plugin 2.2.2 → 2.3.1

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.
Files changed (58) hide show
  1. package/ReadMe.md +2 -0
  2. package/dist/api.js +2 -0
  3. package/dist/chunker/factory.js +48 -18
  4. package/dist/chunker/image.js +6 -0
  5. package/dist/cli/commands/clear.js +21 -1
  6. package/dist/cli/commands/init-helpers.d.ts +4 -1
  7. package/dist/cli/commands/init-helpers.js +55 -20
  8. package/dist/cli/commands/init.js +13 -1
  9. package/dist/cli/commands/query.js +6 -0
  10. package/dist/cli/commands/setup.js +43 -12
  11. package/dist/cli/commands/status.js +4 -0
  12. package/dist/cli/commands/update.d.ts +3 -2
  13. package/dist/cli/commands/update.js +7 -3
  14. package/dist/core/bootstrap.d.ts +3 -1
  15. package/dist/core/bootstrap.js +5 -0
  16. package/dist/core/config.d.ts +74 -1
  17. package/dist/core/config.js +63 -1
  18. package/dist/core/interfaces.d.ts +34 -0
  19. package/dist/core/package-manager.d.ts +69 -0
  20. package/dist/core/package-manager.js +250 -0
  21. package/dist/core/setup-runtime.d.ts +7 -4
  22. package/dist/core/setup-runtime.js +33 -31
  23. package/dist/core/version-check.d.ts +19 -11
  24. package/dist/core/version-check.js +30 -11
  25. package/dist/describer/describer.js +9 -1
  26. package/dist/embedder/factory.d.ts +5 -1
  27. package/dist/embedder/factory.js +76 -6
  28. package/dist/embedder/health.d.ts +1 -1
  29. package/dist/embedder/health.js +43 -0
  30. package/dist/eval/rerank-eval.d.ts +45 -0
  31. package/dist/eval/rerank-eval.js +581 -0
  32. package/dist/indexer/pipeline.d.ts +17 -0
  33. package/dist/indexer/pipeline.js +123 -3
  34. package/dist/indexer/stats.d.ts +7 -0
  35. package/dist/mcp/handlers.js +3 -0
  36. package/dist/opencode/create-read-tool.js +5 -2
  37. package/dist/plugin.js +67 -6
  38. package/dist/quirks/quirk-store.d.ts +1 -0
  39. package/dist/quirks/quirk-store.js +1 -1
  40. package/dist/quirks/tool-error-recall.d.ts +112 -0
  41. package/dist/quirks/tool-error-recall.js +144 -0
  42. package/dist/reranker/base.d.ts +47 -0
  43. package/dist/reranker/base.js +73 -0
  44. package/dist/reranker/factory.d.ts +16 -0
  45. package/dist/reranker/factory.js +47 -0
  46. package/dist/reranker/llama-server.d.ts +33 -0
  47. package/dist/reranker/llama-server.js +101 -0
  48. package/dist/retriever/keyword-index.d.ts +1 -0
  49. package/dist/retriever/keyword-index.js +1 -1
  50. package/dist/retriever/retriever.d.ts +24 -1
  51. package/dist/retriever/retriever.js +69 -5
  52. package/dist/types/opencode-plugin.d.ts +2 -2
  53. package/dist/v2/v2-adapter.d.ts +6 -1
  54. package/dist/v2/v2-adapter.js +52 -8
  55. package/dist/vectorstore/lancedb.d.ts +1 -1
  56. package/dist/vectorstore/lancedb.js +43 -7
  57. package/dist/web/api.js +5 -0
  58. package/package.json +1 -1
package/ReadMe.md CHANGED
@@ -34,6 +34,8 @@ workspace, and `opencode-rag update` upgrades to a newer release.
34
34
 
35
35
  **Prerequisites:** Node.js v22+, [Ollama](https://ollama.ai) (default) or other LLM-hosters (OpenAI-, Google- or Anthropic-compatible).
36
36
 
37
+ `pnpm add -g opencode-rag-plugin`, `yarn global add opencode-rag-plugin`, and `bun add -g opencode-rag-plugin` work as drop-in replacements for the global install — setup and update detect the package manager that owns the install and never require npm on `PATH`.
38
+
37
39
  > **Contributors / developers:** Clone the repo and use `npm install --legacy-peer-deps; npm run build` — see [Development docs](doc/development.md).
38
40
 
39
41
  ## Key Features
package/dist/api.js CHANGED
@@ -56,6 +56,8 @@ export async function search(query, options = {}) {
56
56
  hybridEnabled: ctx.config.retrieval.hybridSearch?.enabled,
57
57
  queryPrefix: ctx.config.embedding.queryPrefix,
58
58
  explain: options.explain,
59
+ reranker: ctx.reranker,
60
+ reranking: ctx.config.reranking,
59
61
  filter: {
60
62
  pathPatterns: options.pathHints,
61
63
  languages: options.languageHints,
@@ -240,27 +240,57 @@ function splitOversized(chunks, filePath, maxLines = MAX_CHUNK_LINES, maxChars =
240
240
  let currentLines = [];
241
241
  let currentCharCount = 0;
242
242
  let lineOffset = 0;
243
+ const flushWindow = (endLineExclusive) => {
244
+ if (currentLines.length === 0)
245
+ return;
246
+ subChunks.push({
247
+ id: uuid(),
248
+ content: currentLines.join("\n"),
249
+ metadata: {
250
+ filePath,
251
+ startLine: chunk.metadata.startLine + lineOffset,
252
+ endLine: chunk.metadata.startLine + endLineExclusive - 1,
253
+ language: chunk.metadata.language,
254
+ },
255
+ });
256
+ // Seed the next window with the last `overlap` lines so split chunks
257
+ // still share their boundary context.
258
+ const tail = overlap > 0 ? currentLines.slice(Math.max(0, currentLines.length - overlap)) : [];
259
+ currentLines = [...tail];
260
+ currentCharCount = tail.reduce((sum, l) => sum + l.length + 1, 0);
261
+ lineOffset = endLineExclusive - tail.length;
262
+ };
243
263
  for (let i = 0; i < lines.length; i++) {
244
264
  const line = lines[i];
245
265
  const lineLen = line.length + 1;
266
+ // A single line longer than the character budget cannot be split at
267
+ // line boundaries. Hard-wrap it by characters so no chunk exceeds
268
+ // maxChars -- otherwise minified bundles (one long line) become
269
+ // whole-file chunks that exceed the embedding model's context size.
270
+ if (maxChars > 0 && line.length > maxChars) {
271
+ flushWindow(i);
272
+ // The wrapped slices must stay within the character budget, so the
273
+ // overlap lines seeded by flushWindow are intentionally not reused.
274
+ currentLines = [];
275
+ currentCharCount = 0;
276
+ for (let start = 0; start < line.length; start += maxChars) {
277
+ subChunks.push({
278
+ id: uuid(),
279
+ content: line.slice(start, start + maxChars),
280
+ metadata: {
281
+ filePath,
282
+ startLine: chunk.metadata.startLine + i,
283
+ endLine: chunk.metadata.startLine + i,
284
+ language: chunk.metadata.language,
285
+ },
286
+ });
287
+ }
288
+ lineOffset = i + 1;
289
+ continue;
290
+ }
246
291
  if (currentLines.length > 0 &&
247
292
  (currentLines.length >= maxLines || currentCharCount + lineLen > maxChars)) {
248
- subChunks.push({
249
- id: uuid(),
250
- content: currentLines.join("\n"),
251
- metadata: {
252
- filePath,
253
- startLine: chunk.metadata.startLine + lineOffset,
254
- endLine: chunk.metadata.startLine + i - 1,
255
- language: chunk.metadata.language,
256
- },
257
- });
258
- // Seed the next window with the last `overlap` lines so split chunks
259
- // still share their boundary context.
260
- const tail = overlap > 0 ? currentLines.slice(Math.max(0, currentLines.length - overlap)) : [];
261
- currentLines = [...tail];
262
- currentCharCount = tail.reduce((sum, l) => sum + l.length + 1, 0);
263
- lineOffset = i - tail.length;
293
+ flushWindow(i);
264
294
  }
265
295
  currentLines.push(line);
266
296
  currentCharCount += lineLen;
@@ -333,9 +363,9 @@ export async function chunkFile(filePath, content, nodeTypesOverrides, options)
333
363
  chunker = withByteLimit(chunker, options.maxSvgSizeBytes);
334
364
  }
335
365
  }
336
- const chunks = await chunker.chunk(filePath, content);
366
+ let chunks = await chunker.chunk(filePath, content);
337
367
  if (chunks.length === 0) {
338
- return fallbackChunker.chunk(filePath, content);
368
+ chunks = await fallbackChunker.chunk(filePath, content);
339
369
  }
340
370
  const overlap = Math.max(0, options?.chunkOverlap ?? 0);
341
371
  const maxLines = options?.maxChunkSize && options.maxChunkSize > 0 ? options.maxChunkSize : MAX_CHUNK_LINES;
@@ -118,6 +118,7 @@ class OpenAIImageVisionProvider {
118
118
  apiKey;
119
119
  timeoutMs;
120
120
  extraHeaders;
121
+ think;
121
122
  proxy;
122
123
  constructor(config, extraHeaders) {
123
124
  this.baseUrl = config.baseUrl.replace(/\/+$/, "");
@@ -125,6 +126,7 @@ class OpenAIImageVisionProvider {
125
126
  this.apiKey = config.apiKey ?? "";
126
127
  this.timeoutMs = config.timeoutMs;
127
128
  this.extraHeaders = extraHeaders ?? {};
129
+ this.think = config.think;
128
130
  this.proxy = config.proxy;
129
131
  }
130
132
  async describeImage(imageBase64, mimeType, prompt, systemPrompt, abort) {
@@ -147,6 +149,10 @@ class OpenAIImageVisionProvider {
147
149
  model: this.model,
148
150
  messages,
149
151
  max_tokens: 2048,
152
+ // Reasoning models (Qwen3.x / Ornith etc.) think before answering; honor
153
+ // `think: false` for OpenAI-compatible providers by forwarding
154
+ // chat_template_kwargs (llama.cpp / vLLM convention).
155
+ ...(this.think === false ? { chat_template_kwargs: { enable_thinking: false } } : {}),
150
156
  };
151
157
  const headers = {
152
158
  ...this.extraHeaders,
@@ -9,6 +9,7 @@ import path from "node:path";
9
9
  import readline from "node:readline";
10
10
  import { c, resolveCliContext, cleanupContext, logCliError, logCliInfo } from "../format.js";
11
11
  import { manifestPathFor } from "../../core/manifest.js";
12
+ import { indexPathFor } from "../../retriever/keyword-index.js";
12
13
  /**
13
14
  * Prompt the user for a yes/no answer via the terminal.
14
15
  * Returns `true` for "y", `false` for "n", and `undefined` on EOF.
@@ -69,8 +70,27 @@ export function registerClearCommand(program) {
69
70
  }
70
71
  logCliInfo(logFilePath, "clear", `${c.label("Clearing")} ${c.num(prevCount)} indexed chunks...`);
71
72
  await store.clear();
73
+ // Trust, but verify: an interrupted clear used to leave the store AND
74
+ // the manifest completely untouched while printing nothing after the
75
+ // "Clearing…" line. Only drop the manifest/keyword index once the
76
+ // table is provably empty, so a failed clear cannot desynchronise them.
77
+ let remaining;
78
+ try {
79
+ remaining = await store.count();
80
+ }
81
+ catch (err) {
82
+ logCliError(logFilePath, "clear", `\nClear could not be verified: ${err.message}. Manifest and keyword index were left in place.`, err);
83
+ await cleanupContext(ctx);
84
+ process.exit(1);
85
+ }
86
+ if (remaining > 0) {
87
+ logCliError(logFilePath, "clear", `\nClear incomplete: ${remaining} of ${prevCount} chunks are still stored (interrupted, or the store is held open by another process). Manifest and keyword index were left in place.`);
88
+ await cleanupContext(ctx);
89
+ process.exit(1);
90
+ }
72
91
  await fs.unlink(manifestPathFor(ctx.storePath)).catch(() => { });
73
- logCliInfo(logFilePath, "clear", `${c.success("Done.")} vector database cleared.`);
92
+ await fs.unlink(indexPathFor(ctx.storePath)).catch(() => { });
93
+ logCliInfo(logFilePath, "clear", `${c.success("Done.")} vector database cleared (was ${c.num(prevCount)} chunks); manifest and keyword index removed.`);
74
94
  await cleanupContext(ctx);
75
95
  }
76
96
  catch (err) {
@@ -123,6 +123,9 @@ export declare function installPluginFromGlobal(opencodeDir: string, packageName
123
123
  *
124
124
  * @param tuning - Optional embedding batch tuning (auto-detected from the
125
125
  * Ollama backend). Falls back to `DEFAULT_CONFIG` for any omitted field.
126
+ * @param existingConfigRaw - Optional raw text of the config file that is about
127
+ * to be replaced. Its `apiKey` and `vectorDimension` are carried over: a
128
+ * reset must not silently change the store schema or drop provider auth.
126
129
  * @returns A pretty-printed JSON string with all default configuration values.
127
130
  */
128
- export declare function generateDefaultConfigJson(tuning?: Partial<IndexingTuning>): string;
131
+ export declare function generateDefaultConfigJson(tuning?: Partial<IndexingTuning>, existingConfigRaw?: string): string;
@@ -8,8 +8,8 @@
8
8
  import path from "node:path";
9
9
  import os from "node:os";
10
10
  import { existsSync, mkdirSync, rmSync, symlinkSync, } from "node:fs";
11
- import { execSync } from "node:child_process";
12
11
  import { DEFAULT_CONFIG } from "../../core/config.js";
12
+ import { installHint, resolveGlobalInstall } from "../../core/package-manager.js";
13
13
  import { c } from "../format.js";
14
14
  import { BEGIN_MARKER, END_MARKER, buildAgentsMdDirective } from "../../opencode/system-guidance.js";
15
15
  import { getStringRecord, readJsonObject, writeJsonFile, } from "../helpers.js";
@@ -359,28 +359,22 @@ export async function installPluginFromGlobal(opencodeDir, packageName, skipInst
359
359
  const globalPluginDir = path.join(runtimeDir, "node_modules", packageName);
360
360
  const workspaceTarget = path.join(opencodeDir, "node_modules", packageName);
361
361
  if (!existsSync(globalPluginDir)) {
362
- // Fallback: try the global npm prefix
363
- let globalRoot;
364
- try {
365
- globalRoot = execSync("npm root -g", { encoding: "utf-8", timeout: 10_000 }).trim();
366
- }
367
- catch {
368
- throw new Error(`Global plugin cache not found at ${globalPluginDir}. ` +
369
- "Run 'opencode-rag setup' or install globally with 'npm install -g opencode-rag-plugin' first.");
370
- }
371
- const globalNpmPluginDir = path.join(globalRoot, packageName);
372
- if (existsSync(globalNpmPluginDir) && existsSync(path.join(globalNpmPluginDir, "dist", "cli.js"))) {
373
- console.log(` ${c.created("Found:")} ${packageName} in global npm prefix, linking...`);
362
+ // Fallback: locate a global install via any package manager (issue #34:
363
+ // npm may be absent — pnpm/yarn/bun installs must resolve too).
364
+ const install = resolveGlobalInstall(packageName);
365
+ if (install && existsSync(path.join(install.packageDir, "dist", "cli.js"))) {
366
+ const pmLabel = install.pm ? `global ${install.pm} install` : "global install";
367
+ console.log(` ${c.created("Found:")} ${packageName} in ${pmLabel}, linking...`);
374
368
  if (existsSync(workspaceTarget)) {
375
369
  rmSync(workspaceTarget, { recursive: true, force: true });
376
370
  }
377
371
  mkdirSync(path.dirname(workspaceTarget), { recursive: true });
378
- createJunction(globalNpmPluginDir, workspaceTarget);
372
+ createJunction(install.packageDir, workspaceTarget);
379
373
  const cliEntry = path.join(workspaceTarget, "dist", "cli.js");
380
374
  if (existsSync(cliEntry)) {
381
- console.log(` ${c.success("Linked:")} ${packageName} from global npm`);
382
- // Also link @opencode-ai/plugin from global npm
383
- const globalSdkDir = path.join(globalRoot, "@opencode-ai", "plugin");
375
+ console.log(` ${c.success("Linked:")} ${packageName} from the global install`);
376
+ // Also link @opencode-ai/plugin from the same global node_modules
377
+ const globalSdkDir = path.join(install.globalRoot, "@opencode-ai", "plugin");
384
378
  const workspaceSdkDir = path.join(opencodeDir, "node_modules", "@opencode-ai", "plugin");
385
379
  if (existsSync(globalSdkDir) && !existsSync(workspaceSdkDir)) {
386
380
  mkdirSync(path.dirname(workspaceSdkDir), { recursive: true });
@@ -392,14 +386,14 @@ export async function installPluginFromGlobal(opencodeDir, packageName, skipInst
392
386
  cpSync(globalSdkDir, workspaceSdkDir, { recursive: true });
393
387
  }
394
388
  }
395
- console.log(` ${c.success("Linked:")} @opencode-ai/plugin from global npm`);
389
+ console.log(` ${c.success("Linked:")} @opencode-ai/plugin from the global install`);
396
390
  return;
397
391
  }
398
392
  // Junction failed or incomplete — fall through to error
399
393
  rmSync(workspaceTarget, { recursive: true, force: true });
400
394
  }
401
395
  throw new Error(`Global plugin cache not found at ${globalPluginDir}. ` +
402
- "Run 'opencode-rag setup' or install globally with 'npm install -g opencode-rag-plugin' first.");
396
+ `Run 'opencode-rag setup' or install globally first (${installHint(packageName)}).`);
403
397
  }
404
398
  // Remove any stale copy (e.g. from a previous 'npm install' run)
405
399
  if (existsSync(workspaceTarget)) {
@@ -437,20 +431,61 @@ export async function installPluginFromGlobal(opencodeDir, packageName, skipInst
437
431
  "Run 'install.sh compile' / 'install.ps1 compile' to install it.");
438
432
  }
439
433
  }
434
+ /**
435
+ * `embedding` keys that the default template does not model but that MUST
436
+ * survive a rewrite. Losing `vectorDimension` makes the next run fall back to
437
+ * the 384 default (and corrupts a rebuild against a store whose schema is
438
+ * 4096), and `apiKey` is provider auth the template never carries — both are
439
+ * invisible data loss when a user confirms "Overwrite with default config?".
440
+ */
441
+ const PRESERVED_EMBEDDING_KEYS = ["apiKey", "vectorDimension"];
442
+ /**
443
+ * Pick the identity-critical `embedding` keys out of an existing config file so
444
+ * the generated defaults can re-apply them. Malformed input simply yields an
445
+ * empty set (the pure default template).
446
+ */
447
+ function preservedEmbeddingKeys(existingConfigRaw) {
448
+ if (!existingConfigRaw)
449
+ return {};
450
+ try {
451
+ const raw = existingConfigRaw.charCodeAt(0) === 0xfeff
452
+ ? existingConfigRaw.slice(1)
453
+ : existingConfigRaw;
454
+ const parsed = JSON.parse(raw);
455
+ const embedding = parsed?.embedding;
456
+ if (!embedding || typeof embedding !== "object")
457
+ return {};
458
+ const preserved = {};
459
+ for (const key of PRESERVED_EMBEDDING_KEYS) {
460
+ const value = embedding[key];
461
+ if (value !== undefined && value !== null && value !== "") {
462
+ preserved[key] = value;
463
+ }
464
+ }
465
+ return preserved;
466
+ }
467
+ catch {
468
+ return {};
469
+ }
470
+ }
440
471
  /**
441
472
  * Generate the default `opencode-rag.json` configuration content.
442
473
  *
443
474
  * @param tuning - Optional embedding batch tuning (auto-detected from the
444
475
  * Ollama backend). Falls back to `DEFAULT_CONFIG` for any omitted field.
476
+ * @param existingConfigRaw - Optional raw text of the config file that is about
477
+ * to be replaced. Its `apiKey` and `vectorDimension` are carried over: a
478
+ * reset must not silently change the store schema or drop provider auth.
445
479
  * @returns A pretty-printed JSON string with all default configuration values.
446
480
  */
447
- export function generateDefaultConfigJson(tuning) {
481
+ export function generateDefaultConfigJson(tuning, existingConfigRaw) {
448
482
  return JSON.stringify({
449
483
  embedding: {
450
484
  provider: DEFAULT_CONFIG.embedding.provider,
451
485
  baseUrl: DEFAULT_CONFIG.embedding.baseUrl,
452
486
  model: DEFAULT_CONFIG.embedding.model,
453
487
  timeoutMs: DEFAULT_CONFIG.embedding.timeoutMs,
488
+ ...preservedEmbeddingKeys(existingConfigRaw),
454
489
  },
455
490
  indexing: {
456
491
  includeExtensions: DEFAULT_CONFIG.indexing.includeExtensions,
@@ -226,7 +226,19 @@ export async function runWorkspaceInit(options = {}) {
226
226
  detectedTuning = undefined;
227
227
  }
228
228
  }
229
- return generateDefaultConfigJson(detectedTuning);
229
+ // Carry the identity-critical embedding keys (apiKey, vectorDimension)
230
+ // over from the file being replaced: a reset must never downgrade the
231
+ // store schema to the 384 default or drop provider auth.
232
+ let existingRaw;
233
+ if (configExists) {
234
+ try {
235
+ existingRaw = readFileSync(configPath, "utf-8");
236
+ }
237
+ catch {
238
+ existingRaw = undefined;
239
+ }
240
+ }
241
+ return generateDefaultConfigJson(detectedTuning, existingRaw);
230
242
  };
231
243
  if (!configExists) {
232
244
  writeFileSync(configPath, await configContent(), "utf-8");
@@ -8,6 +8,7 @@ import path from "node:path";
8
8
  import pc from "picocolors";
9
9
  import { CODE_SEARCH_FILTER } from "../../core/interfaces.js";
10
10
  import { retrieve } from "../../retriever/retriever.js";
11
+ import { getRerankerFor } from "../../reranker/factory.js";
11
12
  import { c, resolveCliContext, cleanupContext, logCliError, logCliInfo, formatDuration } from "../format.js";
12
13
  import { optimizeContext, DEFAULT_CONTEXT_OPTIMIZATION } from "../../retriever/context-optimizer.js";
13
14
  /**
@@ -54,6 +55,8 @@ export function registerQueryCommand(program) {
54
55
  keywordWeight: hybridCfg?.keywordWeight,
55
56
  hybridEnabled: hybridCfg?.enabled,
56
57
  queryPrefix: config.embedding.queryPrefix,
58
+ reranker: getRerankerFor(config.reranking) ?? undefined,
59
+ reranking: config.reranking,
57
60
  explain: options.explain ?? false,
58
61
  filter: CODE_SEARCH_FILTER,
59
62
  });
@@ -72,6 +75,9 @@ export function registerQueryCommand(program) {
72
75
  if (r.explanation) {
73
76
  const sb = r.explanation.scoreBreakdown;
74
77
  logCliInfo(logFilePath, "query", ` ${c.label(" Vector:")} ${c.score(sb.rawVectorScore.toFixed(4))} ${c.label("Keyword:")} ${c.score(sb.rawKeywordScore.toFixed(4))} ${c.label("KW weight:")} ${sb.keywordWeight.toFixed(2)}`);
78
+ if (sb.rerankScore !== undefined) {
79
+ logCliInfo(logFilePath, "query", ` ${c.label(" Rerank:")} ${c.score(sb.rerankScore.toFixed(4))}`);
80
+ }
75
81
  if (r.explanation.matchedTerms && r.explanation.matchedTerms.length > 0) {
76
82
  logCliInfo(logFilePath, "query", ` ${c.label(" Matched:")} ${c.lang(r.explanation.matchedTerms.join(", "))}`);
77
83
  }
@@ -5,6 +5,7 @@ import { c } from "../format.js";
5
5
  import { getPackageMetadata } from "../helpers.js";
6
6
  import { getRuntimeDir, getVersionFile, readVersionFile, setupRuntime, } from "../../core/setup-runtime.js";
7
7
  import { compareVersions, getCurrentVersion, installLatestUpdate } from "../../core/version-check.js";
8
+ import { bestAvailablePackageManager, globalUninstallCommand } from "../../core/package-manager.js";
8
9
  import { isLikelyProjectRoot, isWorkspaceInitialized, runWorkspaceInit } from "./init.js";
9
10
  const PLUGIN_NAME = "opencode-rag-plugin";
10
11
  function removeIfExists(targetPath) {
@@ -98,7 +99,8 @@ export function registerSetupCommand(program) {
98
99
  removeIfExists(versionFile);
99
100
  console.log(` ${c.updated("Removed:")} ${c.file(runtimePluginDir)}`);
100
101
  console.log(` ${c.updated("Removed:")} ${c.file(runtimeSdkPluginDir)}`);
101
- console.log(`\n ${c.success("Done.")} Run ${c.file("npm uninstall -g opencode-rag-plugin")} to remove the global package.\n`);
102
+ const uninstallPm = bestAvailablePackageManager() ?? "npm";
103
+ console.log(`\n ${c.success("Done.")} Run ${c.file(globalUninstallCommand(uninstallPm, PLUGIN_NAME))} to remove the global package.\n`);
102
104
  return;
103
105
  }
104
106
  // --- install ---
@@ -161,9 +163,9 @@ export function registerSetupCommand(program) {
161
163
  */
162
164
  async function ensureUpToDate() {
163
165
  const current = getCurrentVersion();
164
- const latest = getLatestNpmVersion();
166
+ const latest = await getLatestNpmVersion();
165
167
  if (!latest) {
166
- console.log(` ${c.dim("Could not check npm for the latest version (offline?).")}`);
168
+ console.log(` ${c.dim("Could not check the npm registry for the latest version (offline?).")}`);
167
169
  console.log(` ${c.dim("Run `opencode-rag update` later to upgrade.\n")}`);
168
170
  return;
169
171
  }
@@ -184,20 +186,49 @@ async function ensureUpToDate() {
184
186
  /**
185
187
  * Query the npm registry for the latest published version of the plugin.
186
188
  *
187
- * Best-effort: returns `null` when npm is unavailable or the lookup fails.
189
+ * Fetches the registry over HTTPS directly so the check works no matter which
190
+ * package manager installed this CLI — the npm binary may not even exist on
191
+ * machines set up via pnpm/yarn/bun (GitHub issue #34). Honors
192
+ * `npm_config_registry` (set by all four managers) for private mirrors.
193
+ *
194
+ * Best-effort: returns `null` when every endpoint lookup fails (offline,
195
+ * mirror without the endpoint, malformed response).
188
196
  *
189
197
  * @returns The latest version string, or `null` on failure.
190
198
  */
191
- function getLatestNpmVersion() {
199
+ async function getLatestNpmVersion() {
200
+ const registry = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
201
+ const pkgPath = PLUGIN_NAME.includes("/") ? PLUGIN_NAME.replace("/", "%2F") : PLUGIN_NAME;
202
+ // Prefer the lightweight dist-tags endpoint; fall back to the version
203
+ // document for mirrors that do not implement it.
204
+ const urls = [
205
+ `${registry}/-/package/${pkgPath}/dist-tags`,
206
+ `${registry}/${pkgPath}/latest`,
207
+ ];
208
+ const controller = new AbortController();
209
+ const timeout = setTimeout(() => controller.abort(), 15_000);
192
210
  try {
193
- const out = execSync(`npm view ${PLUGIN_NAME} dist-tags.latest`, {
194
- encoding: "utf-8",
195
- timeout: 15_000,
196
- }).trim();
197
- return out || null;
198
- }
199
- catch {
211
+ for (const url of urls) {
212
+ try {
213
+ const response = await fetch(url, {
214
+ headers: { Accept: "application/json" },
215
+ signal: controller.signal,
216
+ });
217
+ if (!response.ok)
218
+ continue;
219
+ const data = (await response.json());
220
+ const version = data.latest ?? data.version;
221
+ if (typeof version === "string" && version)
222
+ return version;
223
+ }
224
+ catch {
225
+ // Try the next endpoint.
226
+ }
227
+ }
200
228
  return null;
201
229
  }
230
+ finally {
231
+ clearTimeout(timeout);
232
+ }
202
233
  }
203
234
  //# sourceMappingURL=setup.js.map
@@ -100,6 +100,10 @@ export function registerStatusCommand(program) {
100
100
  logCliInfo(logFilePath, "status", `${c.label("Pending files:")} ${c.num(summary.pendingFiles)}`);
101
101
  logCliInfo(logFilePath, "status", `${c.label("Indexed chunks:")} ${c.num(summary.storeChunkCount)}`);
102
102
  logCliInfo(logFilePath, "status", `${c.label("Expected chunks:")} ${c.num(summary.manifestExpectedChunks)}`);
103
+ logCliInfo(logFilePath, "status", `${c.label("Orphan chunks:")} ${c.num(summary.orphanChunks)}`);
104
+ if (summary.orphanChunks > 0) {
105
+ logCliInfo(logFilePath, "status", `${c.label("Unaccounted rows:")} ${c.warn("yes")} — stored chunks no manifest entry owns (files whose embedding never completed). Run 'opencode-rag index' to sweep them.`);
106
+ }
103
107
  // Read watcher status from the background auto-indexer
104
108
  const watcherStatusPath = path.join(storePath, "watcher-status.json");
105
109
  let watchModeDisplay;
@@ -3,8 +3,9 @@
3
3
  */
4
4
  /**
5
5
  * `update` command — checks for a newer published version of OpenCodeRAG and,
6
- * by default, installs it (via `npm install -g ...@latest`) then re-syncs the
7
- * OpenCode runtime junctions so the new build is picked up on next restart.
6
+ * by default, installs it via the package manager that owns the global install
7
+ * (npm/pnpm/yarn/bun, `<pkg>@latest`) then re-syncs the OpenCode runtime
8
+ * junctions so the new build is picked up on next restart.
8
9
  */
9
10
  import type { Command } from "commander";
10
11
  /**
@@ -3,11 +3,14 @@
3
3
  */
4
4
  /**
5
5
  * `update` command — checks for a newer published version of OpenCodeRAG and,
6
- * by default, installs it (via `npm install -g ...@latest`) then re-syncs the
7
- * OpenCode runtime junctions so the new build is picked up on next restart.
6
+ * by default, installs it via the package manager that owns the global install
7
+ * (npm/pnpm/yarn/bun, `<pkg>@latest`) then re-syncs the OpenCode runtime
8
+ * junctions so the new build is picked up on next restart.
8
9
  */
9
10
  import { c } from "../format.js";
10
11
  import { checkForUpdate, getCurrentVersion, installLatestUpdate } from "../../core/version-check.js";
12
+ import { bestAvailablePackageManager, globalInstallCommand } from "../../core/package-manager.js";
13
+ const PLUGIN_NAME = "opencode-rag-plugin";
11
14
  /**
12
15
  * Register the `update` command on the given Commander program.
13
16
  *
@@ -56,7 +59,8 @@ export function registerUpdateCommand(program) {
56
59
  else {
57
60
  console.error(` ${c.error("✗")} ${result.message}`);
58
61
  console.error(`\n ${c.error("Update failed. You can retry with `opencode-rag update` or install manually:")}\n`);
59
- console.error(` ${c.dim(" npm install -g opencode-rag-plugin@latest && opencode-rag setup")}\n`);
62
+ const hintPm = bestAvailablePackageManager() ?? "npm";
63
+ console.error(` ${c.dim(` ${globalInstallCommand(hintPm, `${PLUGIN_NAME}@latest`)} && opencode-rag setup`)}\n`);
60
64
  process.exit(1);
61
65
  }
62
66
  });
@@ -3,7 +3,7 @@
3
3
  * creates embedder, vector store, keyword index, and description provider.
4
4
  */
5
5
  import { type RagConfig } from "./config.js";
6
- import type { EmbeddingProvider, VectorStore, KeywordIndex as IKeywordIndex, DescriptionProvider } from "./interfaces.js";
6
+ import type { EmbeddingProvider, RerankProvider, VectorStore, KeywordIndex as IKeywordIndex, DescriptionProvider } from "./interfaces.js";
7
7
  /** Options for bootstrapping the RAG pipeline context. */
8
8
  export interface BootstrapOptions {
9
9
  /** Working directory for resolving config and store paths. Defaults to process.cwd(). */
@@ -31,6 +31,8 @@ export interface RagContext {
31
31
  keywordIndex: IKeywordIndex;
32
32
  /** Optional LLM-based description provider. */
33
33
  descriptionProvider?: DescriptionProvider;
34
+ /** Cross-encoder reranker for the retrieval stage (undefined when disabled). */
35
+ reranker?: RerankProvider;
34
36
  /** Detected embedding dimension. */
35
37
  dimension: number;
36
38
  /** Resolved path to the debug log file. */
@@ -9,6 +9,7 @@ import { loadChunkersFromConfig } from "../chunker/loader.js";
9
9
  import { createEmbedder, probeEmbeddingDimension } from "../embedder/factory.js";
10
10
  import { createDescriptionProvider } from "../describer/factory.js";
11
11
  import { createVectorStore } from "../vectorstore/factory.js";
12
+ import { getRerankerFor } from "../reranker/factory.js";
12
13
  import { readStoreDimension } from "../vectorstore/lancedb.js";
13
14
  import { KeywordIndex } from "../retriever/keyword-index.js";
14
15
  import { reconcileQuirks } from "../quirks/quirk-store.js";
@@ -119,6 +120,9 @@ export async function resolveRagContext(opts = {}) {
119
120
  const descriptionProvider = descriptionConfig?.enabled
120
121
  ? createDescriptionProvider(descriptionConfig)
121
122
  : undefined;
123
+ // Optional cross-encoder reranker (process-wide singleton per endpoint so
124
+ // cooldown + score cache survive across retrievals). Null/disabled by default.
125
+ const reranker = getRerankerFor(cfg.reranking) ?? undefined;
122
126
  return {
123
127
  config: cfg,
124
128
  embedder,
@@ -126,6 +130,7 @@ export async function resolveRagContext(opts = {}) {
126
130
  storePath,
127
131
  keywordIndex,
128
132
  descriptionProvider,
133
+ reranker,
129
134
  dimension,
130
135
  logFilePath,
131
136
  configPath,