opencode-rag-plugin 2.2.2 → 2.3.0
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/api.js +2 -0
- package/dist/chunker/factory.js +48 -18
- package/dist/chunker/image.js +6 -0
- package/dist/cli/commands/clear.js +21 -1
- package/dist/cli/commands/query.js +6 -0
- package/dist/cli/commands/status.js +4 -0
- package/dist/core/bootstrap.d.ts +3 -1
- package/dist/core/bootstrap.js +5 -0
- package/dist/core/config.d.ts +69 -1
- package/dist/core/config.js +63 -1
- package/dist/core/interfaces.d.ts +34 -0
- package/dist/describer/describer.js +9 -1
- package/dist/embedder/factory.d.ts +5 -1
- package/dist/embedder/factory.js +76 -6
- package/dist/embedder/health.d.ts +1 -1
- package/dist/embedder/health.js +43 -0
- package/dist/eval/rerank-eval.d.ts +45 -0
- package/dist/eval/rerank-eval.js +581 -0
- package/dist/indexer/pipeline.d.ts +17 -0
- package/dist/indexer/pipeline.js +123 -3
- package/dist/indexer/stats.d.ts +7 -0
- package/dist/mcp/handlers.js +3 -0
- package/dist/opencode/create-read-tool.js +5 -2
- package/dist/plugin.js +67 -6
- package/dist/quirks/quirk-store.d.ts +1 -0
- package/dist/quirks/quirk-store.js +1 -1
- package/dist/quirks/tool-error-recall.d.ts +112 -0
- package/dist/quirks/tool-error-recall.js +144 -0
- package/dist/reranker/base.d.ts +47 -0
- package/dist/reranker/base.js +73 -0
- package/dist/reranker/factory.d.ts +16 -0
- package/dist/reranker/factory.js +47 -0
- package/dist/reranker/llama-server.d.ts +33 -0
- package/dist/reranker/llama-server.js +101 -0
- package/dist/retriever/keyword-index.d.ts +1 -0
- package/dist/retriever/keyword-index.js +1 -1
- package/dist/retriever/retriever.d.ts +24 -1
- package/dist/retriever/retriever.js +69 -5
- package/dist/types/opencode-plugin.d.ts +2 -2
- package/dist/v2/v2-adapter.d.ts +6 -1
- package/dist/v2/v2-adapter.js +52 -8
- package/dist/vectorstore/lancedb.d.ts +1 -1
- package/dist/vectorstore/lancedb.js +43 -7
- package/dist/web/api.js +5 -0
- package/package.json +1 -1
package/dist/v2/v2-adapter.js
CHANGED
|
@@ -27,6 +27,40 @@
|
|
|
27
27
|
* - The read-tool override keeps its V1 execute contract (args + sessionID).
|
|
28
28
|
*/
|
|
29
29
|
import { ragPlugin } from "../plugin.js";
|
|
30
|
+
/**
|
|
31
|
+
* Extract a human-readable error string from a V2 `execute.after` error event.
|
|
32
|
+
* The exact error payload differs across OpenCode versions; probe the known
|
|
33
|
+
* shapes and fall back to a JSON dump or a generic message.
|
|
34
|
+
*/
|
|
35
|
+
function extractToolErrorText(event) {
|
|
36
|
+
const result = event.result;
|
|
37
|
+
const candidates = [
|
|
38
|
+
event.error,
|
|
39
|
+
event.message,
|
|
40
|
+
result?.error,
|
|
41
|
+
result?.message,
|
|
42
|
+
typeof result?.content === "string" ? result.content : undefined,
|
|
43
|
+
result?.output,
|
|
44
|
+
];
|
|
45
|
+
for (const candidate of candidates) {
|
|
46
|
+
if (typeof candidate === "string" && candidate.trim().length > 0)
|
|
47
|
+
return candidate;
|
|
48
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
49
|
+
const message = candidate.message;
|
|
50
|
+
if (typeof message === "string" && message.trim().length > 0)
|
|
51
|
+
return message;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (result !== undefined) {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.stringify(result);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// circular payload — fall through to the generic message
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return "unknown tool error";
|
|
63
|
+
}
|
|
30
64
|
// ────────────────────────────────────────────────────────────────────────────
|
|
31
65
|
// V1 tool (`@opencode-ai/plugin/tool`, zod-backed) → V2 Tool.Info converter
|
|
32
66
|
// ────────────────────────────────────────────────────────────────────────────
|
|
@@ -169,19 +203,29 @@ export async function registerRagPluginV2(ctx) {
|
|
|
169
203
|
registrations.push(registration);
|
|
170
204
|
}
|
|
171
205
|
// ── tool.execute.after ───────────────────────────────────────────────────
|
|
206
|
+
// Forwards BOTH branches: completed calls keep the existing contract, error
|
|
207
|
+
// calls additionally carry `input.status = "error"` and `output.error`, so
|
|
208
|
+
// the V1-side handler (tool-error quirk injection, auto-capture) can see
|
|
209
|
+
// failed tool calls. Previously the error branch was silently dropped.
|
|
172
210
|
const toolAfterHook = hooks["tool.execute.after"];
|
|
173
211
|
if (toolAfterHook) {
|
|
174
212
|
const registration = await ctx.tool.hook("execute.after", async (event) => {
|
|
175
213
|
try {
|
|
176
|
-
|
|
177
|
-
return;
|
|
214
|
+
const isError = event.status === "error";
|
|
178
215
|
const result = event.result;
|
|
179
|
-
const outputText =
|
|
180
|
-
?
|
|
181
|
-
: result?.
|
|
182
|
-
?
|
|
183
|
-
:
|
|
184
|
-
|
|
216
|
+
const outputText = isError
|
|
217
|
+
? extractToolErrorText(event)
|
|
218
|
+
: typeof result?.content === "string"
|
|
219
|
+
? result.content
|
|
220
|
+
: result?.output !== undefined
|
|
221
|
+
? JSON.stringify(result.output)
|
|
222
|
+
: "";
|
|
223
|
+
await toolAfterHook({
|
|
224
|
+
sessionID: event.sessionID,
|
|
225
|
+
tool: event.tool,
|
|
226
|
+
callID: event.id,
|
|
227
|
+
status: isError ? "error" : "completed",
|
|
228
|
+
}, { output: outputText, error: isError ? outputText : undefined });
|
|
185
229
|
}
|
|
186
230
|
catch {
|
|
187
231
|
// Non-critical — must never throw
|
|
@@ -364,7 +364,7 @@ export declare class LanceDbStore implements VectorStore {
|
|
|
364
364
|
close(): Promise<void>;
|
|
365
365
|
/**
|
|
366
366
|
* Back up the chunks.lance directory before a destructive operation.
|
|
367
|
-
*
|
|
367
|
+
* Moves it to a timestamped `chunks.lance.backup-<ISO timestamp>` directory.
|
|
368
368
|
* Skips if chunks.lance doesn't exist or noBackup is set.
|
|
369
369
|
* @returns The backup path, or null if nothing was backed up.
|
|
370
370
|
*/
|
|
@@ -1341,7 +1341,7 @@ export class LanceDbStore {
|
|
|
1341
1341
|
}
|
|
1342
1342
|
/**
|
|
1343
1343
|
* Back up the chunks.lance directory before a destructive operation.
|
|
1344
|
-
*
|
|
1344
|
+
* Moves it to a timestamped `chunks.lance.backup-<ISO timestamp>` directory.
|
|
1345
1345
|
* Skips if chunks.lance doesn't exist or noBackup is set.
|
|
1346
1346
|
* @returns The backup path, or null if nothing was backed up.
|
|
1347
1347
|
*/
|
|
@@ -1357,8 +1357,26 @@ export class LanceDbStore {
|
|
|
1357
1357
|
}
|
|
1358
1358
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
1359
1359
|
const backupPath = `${lancePath}.backup-${timestamp}`;
|
|
1360
|
-
|
|
1361
|
-
|
|
1360
|
+
// Moving the table directory is instantaneous. Copying it first — as this
|
|
1361
|
+
// used to do — takes minutes on a large store and was exactly the window
|
|
1362
|
+
// in which users interrupted `clear`, ending up with a backup directory
|
|
1363
|
+
// and a completely untouched store. Copy is only the fallback for cases
|
|
1364
|
+
// where a rename cannot work (different volume, or locked by another
|
|
1365
|
+
// process on Windows).
|
|
1366
|
+
try {
|
|
1367
|
+
await fs.rename(lancePath, backupPath);
|
|
1368
|
+
return backupPath;
|
|
1369
|
+
}
|
|
1370
|
+
catch (renameErr) {
|
|
1371
|
+
try {
|
|
1372
|
+
await fs.cp(lancePath, backupPath, { recursive: true });
|
|
1373
|
+
return backupPath;
|
|
1374
|
+
}
|
|
1375
|
+
catch (cpErr) {
|
|
1376
|
+
throw new Error(`Could not back up ${lancePath} before clearing: ` +
|
|
1377
|
+
`${renameErr.message}; copy fallback: ${cpErr.message}`);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1362
1380
|
}
|
|
1363
1381
|
/**
|
|
1364
1382
|
* Remove all chunks by dropping the underlying LanceDB table.
|
|
@@ -1372,18 +1390,36 @@ export class LanceDbStore {
|
|
|
1372
1390
|
await this.table?.close();
|
|
1373
1391
|
this.table = null;
|
|
1374
1392
|
this.knownDimension = null;
|
|
1393
|
+
// The backup normally MOVES chunks.lance away, so there is no table left
|
|
1394
|
+
// to drop; attempting it on a moved table can throw, and the destructive
|
|
1395
|
+
// fallback below would then delete the whole store directory — including
|
|
1396
|
+
// the fresh backup, the manifest and quirks.jsonl.
|
|
1397
|
+
let tableDirStillThere = true;
|
|
1398
|
+
try {
|
|
1399
|
+
await fs.access(path.join(this.dbPath, "chunks.lance"));
|
|
1400
|
+
}
|
|
1401
|
+
catch {
|
|
1402
|
+
tableDirStillThere = false;
|
|
1403
|
+
}
|
|
1375
1404
|
try {
|
|
1376
1405
|
const db = await this.getDb();
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1406
|
+
if (tableDirStillThere) {
|
|
1407
|
+
const tableNames = await db.tableNames();
|
|
1408
|
+
if (tableNames.includes(TABLE_NAME)) {
|
|
1409
|
+
await db.dropTable(TABLE_NAME);
|
|
1410
|
+
}
|
|
1380
1411
|
}
|
|
1381
1412
|
await this.db?.close();
|
|
1382
1413
|
this.db = null;
|
|
1383
1414
|
}
|
|
1384
|
-
catch {
|
|
1415
|
+
catch (err) {
|
|
1385
1416
|
await this.db?.close();
|
|
1386
1417
|
this.db = null;
|
|
1418
|
+
if (backup) {
|
|
1419
|
+
// The backup lives inside this directory — never run the destructive
|
|
1420
|
+
// fallback, it would destroy the backup together with the store.
|
|
1421
|
+
throw err;
|
|
1422
|
+
}
|
|
1387
1423
|
try {
|
|
1388
1424
|
await fs.rm(this.dbPath, { recursive: true, force: true });
|
|
1389
1425
|
}
|
package/dist/web/api.js
CHANGED
|
@@ -5,6 +5,7 @@ import { listSessions, getSession, deleteSession, compareSessions, validateSessi
|
|
|
5
5
|
import { analyzeTokenUsage, compareTokenAnalyses, projectTokenSavings } from "../eval/token-analysis.js";
|
|
6
6
|
import { listQuirks, lintQuirks, removeQuirk } from "../quirks/quirk-store.js";
|
|
7
7
|
import { retrieve } from "../retriever/retriever.js";
|
|
8
|
+
import { getRerankerFor } from "../reranker/factory.js";
|
|
8
9
|
import { updateConfigValue } from "../core/config.js";
|
|
9
10
|
import { createExcludeMatcher } from "../core/exclude.js";
|
|
10
11
|
import { CODE_SEARCH_FILTER } from "../core/interfaces.js";
|
|
@@ -481,6 +482,8 @@ async function handleRetrieve(store, keywordIndex, getEmbedder, cfg, params) {
|
|
|
481
482
|
hybridEnabled: hybrid,
|
|
482
483
|
queryPrefix: cfg.embedding.queryPrefix,
|
|
483
484
|
explain,
|
|
485
|
+
reranker: getRerankerFor(cfg.reranking) ?? undefined,
|
|
486
|
+
reranking: cfg.reranking,
|
|
484
487
|
filter: {
|
|
485
488
|
pathPatterns: pathFilter ? pathFilter.split(",").map((s) => s.trim()).filter(Boolean) : undefined,
|
|
486
489
|
languages: langFilter ? langFilter.split(",").map((s) => s.trim()).filter(Boolean) : undefined,
|
|
@@ -514,7 +517,9 @@ async function handleRetrieve(store, keywordIndex, getEmbedder, cfg, params) {
|
|
|
514
517
|
keywordWeight: r.explanation.scoreBreakdown.keywordWeight,
|
|
515
518
|
vectorRank: r.explanation.scoreBreakdown.vectorRank,
|
|
516
519
|
keywordRank: r.explanation.scoreBreakdown.keywordRank,
|
|
520
|
+
rerankScore: r.explanation.scoreBreakdown.rerankScore,
|
|
517
521
|
},
|
|
522
|
+
confidence: r.explanation.confidence,
|
|
518
523
|
matchedTerms: r.explanation.matchedTerms,
|
|
519
524
|
}
|
|
520
525
|
: undefined,
|