opencode-rag-plugin 1.23.2 → 2.0.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 +3 -0
- package/dist/chunker/factory.d.ts +4 -0
- package/dist/chunker/factory.js +36 -7
- package/dist/cli/commands/init-helpers.d.ts +2 -0
- package/dist/cli/commands/init-helpers.js +2 -5
- package/dist/core/chunk-role.d.ts +22 -0
- package/dist/core/chunk-role.js +47 -0
- package/dist/core/config.d.ts +19 -3
- package/dist/core/config.js +24 -4
- package/dist/core/interfaces.d.ts +10 -0
- package/dist/index.d.ts +2 -10
- package/dist/index.js +1 -7
- package/dist/indexer/pipeline.js +6 -0
- package/dist/indexer/worker.d.ts +2 -0
- package/dist/indexer/worker.js +2 -0
- package/dist/opencode/create-read-tool.js +2 -2
- package/dist/opencode/tools.js +7 -7
- package/dist/plugin-entry.d.ts +10 -12
- package/dist/plugin-entry.js +22 -8
- package/dist/plugin.js +10 -8
- package/dist/retriever/context-optimizer.js +13 -1
- package/dist/retriever/keyword-index.d.ts +15 -0
- package/dist/retriever/keyword-index.js +119 -7
- package/dist/retriever/retriever.d.ts +7 -0
- package/dist/retriever/retriever.js +56 -4
- package/dist/tui.d.ts +85 -2
- package/dist/tui.js +319 -378
- package/dist/v2/v2-adapter.d.ts +103 -0
- package/dist/v2/v2-adapter.js +226 -0
- package/dist/vectorstore/lancedb.d.ts +1 -1
- package/dist/vectorstore/lancedb.js +12 -4
- package/dist/vectorstore/memory.js +1 -0
- package/dist/web/ui/assets/ScatterPlot3D-CKwyh1Ec.js +4108 -0
- package/dist/web/ui/assets/index-Cgv1RsGv.js +4 -0
- package/dist/web/ui/assets/index-DjJHIo9R.css +1 -0
- package/dist/web/ui/assets/vendor-Dg8wMT7C.js +1 -0
- package/dist/web/ui/index.html +3 -3
- package/package.json +16 -11
- package/dist/web/ui/assets/ScatterPlot3D-DQLl3sKN.js +0 -4116
- package/dist/web/ui/assets/index-BZh9MitV.js +0 -4
- package/dist/web/ui/assets/index-DKhjGsql.css +0 -1
- package/dist/web/ui/assets/vendor-Dy7HKFCY.js +0 -1
package/dist/api.js
CHANGED
|
@@ -50,6 +50,9 @@ export async function search(query, options = {}) {
|
|
|
50
50
|
minScore: options.minScore ?? ctx.config.retrieval.minScore,
|
|
51
51
|
keywordIndex: ctx.keywordIndex,
|
|
52
52
|
keywordWeight: options.keywordWeight ?? ctx.config.retrieval.hybridSearch?.keywordWeight ?? 0.4,
|
|
53
|
+
symbolKeywordWeight: ctx.config.retrieval.hybridSearch?.symbolKeywordWeight,
|
|
54
|
+
docKeywordDemotion: ctx.config.retrieval.hybridSearch?.docKeywordDemotion,
|
|
55
|
+
testKeywordDemotion: ctx.config.retrieval.hybridSearch?.testKeywordDemotion,
|
|
53
56
|
hybridEnabled: ctx.config.retrieval.hybridSearch?.enabled,
|
|
54
57
|
queryPrefix: ctx.config.embedding.queryPrefix,
|
|
55
58
|
explain: options.explain,
|
|
@@ -64,5 +64,9 @@ export declare function getRegisteredExtensions(): string[];
|
|
|
64
64
|
*/
|
|
65
65
|
export declare function chunkFile(filePath: string, content: string, nodeTypesOverrides?: Record<string, string[]>, options?: {
|
|
66
66
|
maxSvgSizeBytes?: number;
|
|
67
|
+
/** Maximum lines per chunk; oversized chunks are split into windows. */
|
|
68
|
+
maxChunkSize?: number;
|
|
69
|
+
/** Overlapping lines shared between adjacent/split chunks. */
|
|
70
|
+
chunkOverlap?: number;
|
|
67
71
|
}): Promise<Chunk[]>;
|
|
68
72
|
export { typescriptChunker, pythonChunker, javaChunker, goChunker, markdownChunker, cChunker, cppChunker, csharpChunker, javascriptChunker, razorChunker, jsonChunker, htmlChunker, cssChunker, xmlChunker, slnChunker, rustChunker, rubyChunker, kotlinChunker, swiftChunker, bashChunker, phpChunker, powershellChunker, iniChunker, yamlChunker, tomlChunker, dockerfileChunker, sqlChunker, texChunker, pdfChunker, fallbackChunker };
|
package/dist/chunker/factory.js
CHANGED
|
@@ -120,11 +120,34 @@ export function getRegisteredExtensions() {
|
|
|
120
120
|
}
|
|
121
121
|
const MAX_CHUNK_LINES = 100;
|
|
122
122
|
const MAX_CHUNK_CHARS = 8000;
|
|
123
|
-
|
|
123
|
+
/** Prepend the tail of the previous chunk as context to the next one, so a
|
|
124
|
+
* construct split across a chunk boundary is still retrievable whole. */
|
|
125
|
+
function applyChunkOverlap(chunks, overlap) {
|
|
126
|
+
if (overlap <= 0 || chunks.length <= 1)
|
|
127
|
+
return chunks;
|
|
124
128
|
const result = [];
|
|
129
|
+
let prevTail = null;
|
|
125
130
|
for (const chunk of chunks) {
|
|
126
131
|
const lines = chunk.content.split("\n");
|
|
127
|
-
if (
|
|
132
|
+
if (prevTail && prevTail.length > 0) {
|
|
133
|
+
result.push({
|
|
134
|
+
...chunk,
|
|
135
|
+
id: uuid(),
|
|
136
|
+
content: [...prevTail, ...lines].join("\n"),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
result.push(chunk);
|
|
141
|
+
}
|
|
142
|
+
prevTail = lines.slice(Math.max(0, lines.length - overlap));
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function splitOversized(chunks, filePath, maxLines = MAX_CHUNK_LINES, maxChars = MAX_CHUNK_CHARS, overlap = 0) {
|
|
147
|
+
const result = [];
|
|
148
|
+
for (const chunk of chunks) {
|
|
149
|
+
const lines = chunk.content.split("\n");
|
|
150
|
+
if (lines.length <= maxLines && chunk.content.length <= maxChars) {
|
|
128
151
|
result.push(chunk);
|
|
129
152
|
continue;
|
|
130
153
|
}
|
|
@@ -136,7 +159,7 @@ function splitOversized(chunks, filePath) {
|
|
|
136
159
|
const line = lines[i];
|
|
137
160
|
const lineLen = line.length + 1;
|
|
138
161
|
if (currentLines.length > 0 &&
|
|
139
|
-
(currentLines.length >=
|
|
162
|
+
(currentLines.length >= maxLines || currentCharCount + lineLen > maxChars)) {
|
|
140
163
|
subChunks.push({
|
|
141
164
|
id: uuid(),
|
|
142
165
|
content: currentLines.join("\n"),
|
|
@@ -147,9 +170,12 @@ function splitOversized(chunks, filePath) {
|
|
|
147
170
|
language: chunk.metadata.language,
|
|
148
171
|
},
|
|
149
172
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
173
|
+
// Seed the next window with the last `overlap` lines so split chunks
|
|
174
|
+
// still share their boundary context.
|
|
175
|
+
const tail = overlap > 0 ? currentLines.slice(Math.max(0, currentLines.length - overlap)) : [];
|
|
176
|
+
currentLines = [...tail];
|
|
177
|
+
currentCharCount = tail.reduce((sum, l) => sum + l.length + 1, 0);
|
|
178
|
+
lineOffset = i - tail.length;
|
|
153
179
|
}
|
|
154
180
|
currentLines.push(line);
|
|
155
181
|
currentCharCount += lineLen;
|
|
@@ -226,7 +252,10 @@ export async function chunkFile(filePath, content, nodeTypesOverrides, options)
|
|
|
226
252
|
if (chunks.length === 0) {
|
|
227
253
|
return fallbackChunker.chunk(filePath, content);
|
|
228
254
|
}
|
|
229
|
-
|
|
255
|
+
const overlap = Math.max(0, options?.chunkOverlap ?? 0);
|
|
256
|
+
const maxLines = options?.maxChunkSize && options.maxChunkSize > 0 ? options.maxChunkSize : MAX_CHUNK_LINES;
|
|
257
|
+
const split = splitOversized(chunks, filePath, maxLines, MAX_CHUNK_CHARS, overlap);
|
|
258
|
+
return applyChunkOverlap(split, overlap);
|
|
230
259
|
}
|
|
231
260
|
export { typescriptChunker, pythonChunker, javaChunker, goChunker, markdownChunker, cChunker, cppChunker, csharpChunker, javascriptChunker, razorChunker, jsonChunker, htmlChunker, cssChunker, xmlChunker, slnChunker, rustChunker, rubyChunker, kotlinChunker, swiftChunker, bashChunker, phpChunker, powershellChunker, iniChunker, yamlChunker, tomlChunker, dockerfileChunker, sqlChunker, texChunker, pdfChunker, fallbackChunker };
|
|
232
261
|
//# sourceMappingURL=factory.js.map
|
|
@@ -46,6 +46,8 @@ export declare function removeStaleGlobalPluginRegistrations(homeDir: string, pl
|
|
|
46
46
|
* Generate the content for `.opencode/plugins/rag-plugin.js`.
|
|
47
47
|
*
|
|
48
48
|
* This file re-exports the plugin from the workspace-local node_modules.
|
|
49
|
+
* The plugin entry default-exports the OpenCode V2 module shape
|
|
50
|
+
* (`{ id, setup }`), so a bare default re-export is all that is needed.
|
|
49
51
|
*
|
|
50
52
|
* @param packageName - The npm package name of the RAG plugin.
|
|
51
53
|
* @returns The JavaScript source code for the plugin entry file.
|
|
@@ -137,6 +137,8 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
|
|
|
137
137
|
* Generate the content for `.opencode/plugins/rag-plugin.js`.
|
|
138
138
|
*
|
|
139
139
|
* This file re-exports the plugin from the workspace-local node_modules.
|
|
140
|
+
* The plugin entry default-exports the OpenCode V2 module shape
|
|
141
|
+
* (`{ id, setup }`), so a bare default re-export is all that is needed.
|
|
140
142
|
*
|
|
141
143
|
* @param packageName - The npm package name of the RAG plugin.
|
|
142
144
|
* @returns The JavaScript source code for the plugin entry file.
|
|
@@ -144,8 +146,6 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
|
|
|
144
146
|
export function generateWorkspacePluginFile(packageName) {
|
|
145
147
|
return [
|
|
146
148
|
`import plugin from "../node_modules/${packageName}/dist/plugin-entry.js";`,
|
|
147
|
-
`export const id = plugin.id;`,
|
|
148
|
-
`export const server = plugin.server;`,
|
|
149
149
|
`export default plugin;`,
|
|
150
150
|
"",
|
|
151
151
|
].join("\n");
|
|
@@ -513,9 +513,6 @@ export function generateDefaultConfigJson(tuning) {
|
|
|
513
513
|
level: DEFAULT_CONFIG.logging.level,
|
|
514
514
|
logFilePath: DEFAULT_CONFIG.logging.logFilePath,
|
|
515
515
|
},
|
|
516
|
-
chunking: {
|
|
517
|
-
nodeTypes: {},
|
|
518
|
-
},
|
|
519
516
|
}, null, 2) + "\n";
|
|
520
517
|
}
|
|
521
518
|
//# sourceMappingURL=init-helpers.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Classifies a chunk's provenance (source / test / doc) from its file path.
|
|
3
|
+
*
|
|
4
|
+
* The retrieval fusion uses this to demote documentation and test chunks when they
|
|
5
|
+
* compete on keyword matches — natural-language queries about "how X works" match
|
|
6
|
+
* doc and test files literally (their prose names the concepts), which otherwise
|
|
7
|
+
* lets them outrank the implementation the query is really after.
|
|
8
|
+
*/
|
|
9
|
+
import type { Chunk } from "./interfaces.js";
|
|
10
|
+
export type ChunkRole = "source" | "test" | "doc";
|
|
11
|
+
/**
|
|
12
|
+
* Classify the role of a file from its path. Test takes precedence over doc
|
|
13
|
+
* (a `*.test.md` is a test artifact), and everything else is source.
|
|
14
|
+
*/
|
|
15
|
+
export declare function classifyFilePath(filePath: string): ChunkRole;
|
|
16
|
+
/**
|
|
17
|
+
* Tag a chunk with its derived role. Idempotent — a chunk that already carries a
|
|
18
|
+
* role is returned unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tagChunkRole(chunk: Chunk): Chunk;
|
|
21
|
+
/** Tag all chunks produced for a file with their derived role. */
|
|
22
|
+
export declare function tagChunksRole(chunks: Chunk[]): Chunk[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Classifies a chunk's provenance (source / test / doc) from its file path.
|
|
3
|
+
*
|
|
4
|
+
* The retrieval fusion uses this to demote documentation and test chunks when they
|
|
5
|
+
* compete on keyword matches — natural-language queries about "how X works" match
|
|
6
|
+
* doc and test files literally (their prose names the concepts), which otherwise
|
|
7
|
+
* lets them outrank the implementation the query is really after.
|
|
8
|
+
*/
|
|
9
|
+
const TEST_PATH_SEGMENTS = ["__tests__", "test", "tests", "spec", "specs", "fixtures"];
|
|
10
|
+
const TEST_BASENAME = /\.(?:test|spec|bench)\.[a-z0-9]+$/i;
|
|
11
|
+
const DOC_PATH_SEGMENTS = ["doc", "docs", "documentation"];
|
|
12
|
+
const DOC_EXTENSIONS = [".md", ".mdx", ".rst", ".adoc"];
|
|
13
|
+
/**
|
|
14
|
+
* Classify the role of a file from its path. Test takes precedence over doc
|
|
15
|
+
* (a `*.test.md` is a test artifact), and everything else is source.
|
|
16
|
+
*/
|
|
17
|
+
export function classifyFilePath(filePath) {
|
|
18
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
19
|
+
const segments = normalized.split("/");
|
|
20
|
+
const basename = segments[segments.length - 1] ?? "";
|
|
21
|
+
if (TEST_BASENAME.test(basename))
|
|
22
|
+
return "test";
|
|
23
|
+
if (segments.some((s) => TEST_PATH_SEGMENTS.includes(s.toLowerCase())))
|
|
24
|
+
return "test";
|
|
25
|
+
if (DOC_EXTENSIONS.some((ext) => basename.toLowerCase().endsWith(ext)))
|
|
26
|
+
return "doc";
|
|
27
|
+
if (segments.some((s) => DOC_PATH_SEGMENTS.includes(s.toLowerCase())))
|
|
28
|
+
return "doc";
|
|
29
|
+
return "source";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tag a chunk with its derived role. Idempotent — a chunk that already carries a
|
|
33
|
+
* role is returned unchanged.
|
|
34
|
+
*/
|
|
35
|
+
export function tagChunkRole(chunk) {
|
|
36
|
+
if (chunk.metadata.role)
|
|
37
|
+
return chunk;
|
|
38
|
+
chunk.metadata.role = classifyFilePath(chunk.metadata.filePath);
|
|
39
|
+
return chunk;
|
|
40
|
+
}
|
|
41
|
+
/** Tag all chunks produced for a file with their derived role. */
|
|
42
|
+
export function tagChunksRole(chunks) {
|
|
43
|
+
for (const chunk of chunks)
|
|
44
|
+
tagChunkRole(chunk);
|
|
45
|
+
return chunks;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=chunk-role.js.map
|
package/dist/core/config.d.ts
CHANGED
|
@@ -181,16 +181,20 @@ export interface MemoryConfig {
|
|
|
181
181
|
minConfidence: number;
|
|
182
182
|
/** Minimum query-relevance score (0-1) for a quirk to be recalled. */
|
|
183
183
|
recallMinScore: number;
|
|
184
|
-
/** Minimum relevance score for
|
|
184
|
+
/** Minimum relevance score for quirks to be AUTO-injected into the prompt
|
|
185
|
+
* (both the system-prompt transform and the user message). Deliberately a
|
|
186
|
+
* high bar: injected quirks occupy context on every turn, so only strongly
|
|
187
|
+
* relevant ones should reach the prompt. Manual `recall_quirks` calls use
|
|
188
|
+
* the lower `recallMinScore`. */
|
|
185
189
|
autoInjectMinScore: number;
|
|
186
190
|
/** Maximum latency budget (ms) for auto-inject quirk recall. If exceeded, injection is skipped. */
|
|
187
191
|
autoInjectLatencyBudgetMs: number;
|
|
188
|
-
/** Max quirks to auto-inject per turn (default
|
|
192
|
+
/** Max quirks to auto-inject per turn (default 1). */
|
|
189
193
|
autoInjectTopK: number;
|
|
190
194
|
/**
|
|
191
195
|
* Minimum number of shared word tokens (≥3 chars) between a candidate quirk's
|
|
192
196
|
* content and the user's *current* message for the quirk to be auto-injected
|
|
193
|
-
* (default
|
|
197
|
+
* (default 2). Acts as a relevance gate against meta-quirks that match only
|
|
194
198
|
* the prior assistant text in the combined recall query. Set to `0` to disable.
|
|
195
199
|
*/
|
|
196
200
|
autoInjectMinTokenOverlap: number;
|
|
@@ -319,6 +323,9 @@ export interface RagConfig {
|
|
|
319
323
|
includeDirs?: string[];
|
|
320
324
|
/** Number of overlapping lines between adjacent chunks. */
|
|
321
325
|
chunkOverlap: number;
|
|
326
|
+
/** Maximum lines per chunk — oversized chunks are split into windows with
|
|
327
|
+
* `chunkOverlap` lines of context between them. 0 = no limit (whole AST node). */
|
|
328
|
+
maxChunkSize?: number;
|
|
322
329
|
/** Minimum file size in bytes to index (0 = no minimum). */
|
|
323
330
|
minFileSizeBytes?: number;
|
|
324
331
|
/** Maximum concurrent file processing tasks. */
|
|
@@ -378,6 +385,15 @@ export interface RagConfig {
|
|
|
378
385
|
enabled: boolean;
|
|
379
386
|
/** Weight for keyword scores in fusion (0 = vector only, 1 = keyword only). */
|
|
380
387
|
keywordWeight: number;
|
|
388
|
+
/** Keyword weight for symbol-style queries (a bare identifier like
|
|
389
|
+
* `cosineSimilarity`). Keyword search nails exact symbol matches, so these
|
|
390
|
+
* get a higher weight than natural-language queries. Defaults to keywordWeight. */
|
|
391
|
+
symbolKeywordWeight?: number;
|
|
392
|
+
/** Multiplier (0-1) on the keyword contribution of documentation chunks.
|
|
393
|
+
* Docs name concepts literally and otherwise outrank the implementation. */
|
|
394
|
+
docKeywordDemotion?: number;
|
|
395
|
+
/** Multiplier (0-1) on the keyword contribution of test chunks. */
|
|
396
|
+
testKeywordDemotion?: number;
|
|
381
397
|
};
|
|
382
398
|
/** Context window optimization settings for post-retrieval quality filtering. */
|
|
383
399
|
contextOptimization?: ContextOptimizationConfig;
|
package/dist/core/config.js
CHANGED
|
@@ -111,6 +111,7 @@ export const DEFAULT_CONFIG = {
|
|
|
111
111
|
"package-lock.json",
|
|
112
112
|
],
|
|
113
113
|
chunkOverlap: 0,
|
|
114
|
+
maxChunkSize: 0,
|
|
114
115
|
minFileSizeBytes: 0,
|
|
115
116
|
concurrency: 8,
|
|
116
117
|
embedBatchSize: 100,
|
|
@@ -131,6 +132,9 @@ export const DEFAULT_CONFIG = {
|
|
|
131
132
|
hybridSearch: {
|
|
132
133
|
enabled: true,
|
|
133
134
|
keywordWeight: 0.4,
|
|
135
|
+
symbolKeywordWeight: 0.6,
|
|
136
|
+
docKeywordDemotion: 0.5,
|
|
137
|
+
testKeywordDemotion: 0.6,
|
|
134
138
|
},
|
|
135
139
|
contextOptimization: {
|
|
136
140
|
enabled: true,
|
|
@@ -273,11 +277,11 @@ export const DEFAULT_CONFIG = {
|
|
|
273
277
|
enabled: true,
|
|
274
278
|
autoInject: true,
|
|
275
279
|
minConfidence: 0.5,
|
|
276
|
-
recallMinScore: 0.
|
|
277
|
-
autoInjectMinScore: 0.
|
|
280
|
+
recallMinScore: 0.72,
|
|
281
|
+
autoInjectMinScore: 0.75,
|
|
278
282
|
autoInjectLatencyBudgetMs: 2000,
|
|
279
|
-
autoInjectTopK:
|
|
280
|
-
autoInjectMinTokenOverlap:
|
|
283
|
+
autoInjectTopK: 1,
|
|
284
|
+
autoInjectMinTokenOverlap: 2,
|
|
281
285
|
passiveCapture: true,
|
|
282
286
|
promptEnforcement: true,
|
|
283
287
|
sessionEndExtraction: true,
|
|
@@ -365,6 +369,22 @@ export function validateConfig(config) {
|
|
|
365
369
|
if (kw < 0 || kw > 1) {
|
|
366
370
|
warnings.push("retrieval.hybridSearch.keywordWeight must be between 0 and 1");
|
|
367
371
|
}
|
|
372
|
+
const hs = config.retrieval.hybridSearch;
|
|
373
|
+
if (hs.symbolKeywordWeight != null && (hs.symbolKeywordWeight < 0 || hs.symbolKeywordWeight > 1)) {
|
|
374
|
+
warnings.push("retrieval.hybridSearch.symbolKeywordWeight must be between 0 and 1");
|
|
375
|
+
}
|
|
376
|
+
if (hs.docKeywordDemotion != null && (hs.docKeywordDemotion < 0 || hs.docKeywordDemotion > 1)) {
|
|
377
|
+
warnings.push("retrieval.hybridSearch.docKeywordDemotion must be between 0 and 1");
|
|
378
|
+
}
|
|
379
|
+
if (hs.testKeywordDemotion != null && (hs.testKeywordDemotion < 0 || hs.testKeywordDemotion > 1)) {
|
|
380
|
+
warnings.push("retrieval.hybridSearch.testKeywordDemotion must be between 0 and 1");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (config.indexing.maxChunkSize != null && config.indexing.maxChunkSize < 0) {
|
|
384
|
+
warnings.push("indexing.maxChunkSize must be >= 0");
|
|
385
|
+
}
|
|
386
|
+
if (config.indexing.maxChunkSize && config.indexing.maxChunkSize <= config.indexing.chunkOverlap) {
|
|
387
|
+
warnings.push("indexing.maxChunkSize must be greater than chunkOverlap (otherwise windows make no progress)");
|
|
368
388
|
}
|
|
369
389
|
if (config.memory?.recallMinScore != null) {
|
|
370
390
|
const r = config.memory.recallMinScore;
|
|
@@ -16,6 +16,9 @@ export interface Chunk {
|
|
|
16
16
|
contentType?: string;
|
|
17
17
|
/** Synthetic chunk kind — e.g. "quirk" for experiential memory entries. */
|
|
18
18
|
kind?: string;
|
|
19
|
+
/** Provenance of the file, derived from its path: source / test / doc. Used by
|
|
20
|
+
* hybrid fusion to demote doc/test chunks that match query terms literally. */
|
|
21
|
+
role?: "source" | "test" | "doc";
|
|
19
22
|
/** Quirk sub-type when kind === "quirk": gotcha, preference, decision, environment-constraint. */
|
|
20
23
|
quirkType?: string;
|
|
21
24
|
/** Arbitrary tags for filtering/queries. */
|
|
@@ -79,6 +82,12 @@ export interface SearchExplanation {
|
|
|
79
82
|
/** Rank (0-indexed) in the keyword index results. */
|
|
80
83
|
keywordRank?: number;
|
|
81
84
|
};
|
|
85
|
+
/** Calibrated relevance in [0,1] derived from the raw vector-score spread of the
|
|
86
|
+
* candidate set — unlike the fused `score` (RRF-normalized so rank 0 is always
|
|
87
|
+
* ~1.0), this reflects how confident the match actually is. */
|
|
88
|
+
confidence?: number;
|
|
89
|
+
/** Shape of the query that produced this result ("symbol" vs "natural-language"). */
|
|
90
|
+
queryShape?: "symbol" | "natural-language";
|
|
82
91
|
/** Query terms that matched in the keyword index, if hybrid search was used. */
|
|
83
92
|
matchedTerms?: string[];
|
|
84
93
|
}
|
|
@@ -148,6 +157,7 @@ export interface ChunkSummary {
|
|
|
148
157
|
content: string;
|
|
149
158
|
description: string;
|
|
150
159
|
kind: string;
|
|
160
|
+
role: string;
|
|
151
161
|
quirkType: string;
|
|
152
162
|
tags: string;
|
|
153
163
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,13 +28,5 @@ export type { SearchOptions, IndexOptions, ContextResult, ConfigValidationResult
|
|
|
28
28
|
/** Version check and self-update API. */
|
|
29
29
|
export { checkForUpdate, getCurrentVersion, installLatestUpdate, compareVersions } from "./core/version-check.js";
|
|
30
30
|
export type { UpdateInfo, InstallUpdateResult } from "./core/version-check.js";
|
|
31
|
-
/**
|
|
32
|
-
export
|
|
33
|
-
/** Unique identifier for the OpenCodeRAG plugin. */
|
|
34
|
-
export declare const id = "opencode-rag-plugin";
|
|
35
|
-
/** Default export conforming to OpenCode's plugin module signature. */
|
|
36
|
-
declare const _default: {
|
|
37
|
-
id: string;
|
|
38
|
-
server: import("@opencode-ai/plugin").Plugin;
|
|
39
|
-
};
|
|
40
|
-
export default _default;
|
|
31
|
+
/** Plugin entry — only importable inside OpenCode's runtime. */
|
|
32
|
+
export { id, default } from "./plugin-entry.js";
|
package/dist/index.js
CHANGED
|
@@ -24,11 +24,5 @@ export { search, indexWorkspace, getContext, validateConfig, scanWorkspace, getI
|
|
|
24
24
|
/** Version check and self-update API. */
|
|
25
25
|
export { checkForUpdate, getCurrentVersion, installLatestUpdate, compareVersions } from "./core/version-check.js";
|
|
26
26
|
/** Plugin entry — only importable inside OpenCode's runtime. */
|
|
27
|
-
|
|
28
|
-
/** The plugin server configuration object, used to register OpenCodeRAG as an OpenCode plugin. */
|
|
29
|
-
export const server = ragPlugin;
|
|
30
|
-
/** Unique identifier for the OpenCodeRAG plugin. */
|
|
31
|
-
export const id = "opencode-rag-plugin";
|
|
32
|
-
/** Default export conforming to OpenCode's plugin module signature. */
|
|
33
|
-
export default { id, server: ragPlugin };
|
|
27
|
+
export { id, default } from "./plugin-entry.js";
|
|
34
28
|
//# sourceMappingURL=index.js.map
|
package/dist/indexer/pipeline.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createVectorStore } from "../vectorstore/factory.js";
|
|
|
12
12
|
import { swapStoreDirectories } from "../vectorstore/lancedb.js";
|
|
13
13
|
import { createIndexStats } from "./stats.js";
|
|
14
14
|
import { prepareFile, buildTextsToEmbed } from "./worker.js";
|
|
15
|
+
import { tagChunksRole } from "../core/chunk-role.js";
|
|
15
16
|
import { buildFallbackDescription } from "./description-stage.js";
|
|
16
17
|
import { getCurrentCommit, getChangedFilesSince, getUntrackedFiles, getRepoRoot } from "./git-diff.js";
|
|
17
18
|
export { createWatchPassScheduler, createWatchIgnore } from "./watch.js";
|
|
@@ -410,6 +411,11 @@ async function runIndexPassInner(options, logger) {
|
|
|
410
411
|
options.progress?.startFile(fileLabel);
|
|
411
412
|
}
|
|
412
413
|
const prep = await prepareFile(file, options.cwd, manifest.files[file.normalizedPath], options.config, options.keywordIndex, options.descriptionProvider, logger, deferDescriptions, descHash);
|
|
414
|
+
// Stamp every chunk with its file provenance (source/test/doc) so
|
|
415
|
+
// hybrid fusion can demote docs/tests that match query terms literally.
|
|
416
|
+
if (prep.chunks && prep.chunks.length > 0) {
|
|
417
|
+
tagChunksRole(prep.chunks);
|
|
418
|
+
}
|
|
413
419
|
if (isActive) {
|
|
414
420
|
chunkedDone++;
|
|
415
421
|
if (chunkedDone % chunkProgressInterval === 0 || chunkedDone === activeCount) {
|
package/dist/indexer/worker.d.ts
CHANGED
|
@@ -121,6 +121,8 @@ export declare function prepareFile(file: WorkspaceFile, cwd: string, previous:
|
|
|
121
121
|
indexing?: {
|
|
122
122
|
maxSvgSizeBytes?: number;
|
|
123
123
|
embedDescriptions?: boolean;
|
|
124
|
+
maxChunkSize?: number;
|
|
125
|
+
chunkOverlap?: number;
|
|
124
126
|
};
|
|
125
127
|
}, keywordIndex: KeywordIndex | undefined, descriptionProvider: DescriptionProvider | undefined, logger: Logger, deferDescriptions?: boolean, descHash?: string): Promise<PreparedFile>;
|
|
126
128
|
/**
|
package/dist/indexer/worker.js
CHANGED
|
@@ -117,6 +117,8 @@ export async function prepareFile(file, cwd, previous, config, keywordIndex, des
|
|
|
117
117
|
else {
|
|
118
118
|
chunks = await chunkFile(file.filePath, file.content, config.chunking?.nodeTypes, {
|
|
119
119
|
maxSvgSizeBytes: config.indexing?.maxSvgSizeBytes,
|
|
120
|
+
maxChunkSize: config.indexing?.maxChunkSize,
|
|
121
|
+
chunkOverlap: config.indexing?.chunkOverlap,
|
|
120
122
|
}).catch((err) => {
|
|
121
123
|
logger.warn(` ${fileLabel} (chunking failed: ${err.message})`);
|
|
122
124
|
return null;
|
|
@@ -38,7 +38,7 @@ export function createRagReadTool(options) {
|
|
|
38
38
|
query: tool.schema.string().optional(),
|
|
39
39
|
reason: tool.schema.string().optional(),
|
|
40
40
|
},
|
|
41
|
-
async execute(args,
|
|
41
|
+
async execute(args, _context) {
|
|
42
42
|
let resolvedPath;
|
|
43
43
|
let normalized;
|
|
44
44
|
try {
|
|
@@ -52,7 +52,7 @@ export function createRagReadTool(options) {
|
|
|
52
52
|
let ragChunks = [];
|
|
53
53
|
let relatedFiles = [];
|
|
54
54
|
try {
|
|
55
|
-
const sessionID =
|
|
55
|
+
const sessionID = _context?.sessionID;
|
|
56
56
|
const messageText = sessionID ? sessionLastMessage?.get(sessionID) ?? "" : "";
|
|
57
57
|
const count = await store.count();
|
|
58
58
|
if (count > 0) {
|
package/dist/opencode/tools.js
CHANGED
|
@@ -202,7 +202,7 @@ export function createFileSkeletonTool(options) {
|
|
|
202
202
|
args: {
|
|
203
203
|
filePath: tool.schema.string().min(1, "A file path is required."),
|
|
204
204
|
},
|
|
205
|
-
async execute(args) {
|
|
205
|
+
async execute(args, _context) {
|
|
206
206
|
try {
|
|
207
207
|
const resolvedPath = resolveFilePath(args.filePath, worktree);
|
|
208
208
|
const content = readFileSync(resolvedPath, "utf-8");
|
|
@@ -266,7 +266,7 @@ export function createDescribeImageTool(options) {
|
|
|
266
266
|
filePath: tool.schema.string().min(1, "An image file path is required."),
|
|
267
267
|
systemPrompt: tool.schema.string().optional(),
|
|
268
268
|
},
|
|
269
|
-
async execute(args) {
|
|
269
|
+
async execute(args, _context) {
|
|
270
270
|
try {
|
|
271
271
|
const { existsSync, readFileSync } = await import("node:fs");
|
|
272
272
|
const path = await import("node:path");
|
|
@@ -396,7 +396,7 @@ export function createFindUsagesTool(options) {
|
|
|
396
396
|
pathHint: tool.schema.string().optional(),
|
|
397
397
|
topK: tool.schema.number().int().min(1).max(50).optional(),
|
|
398
398
|
},
|
|
399
|
-
async execute(args) {
|
|
399
|
+
async execute(args, _context) {
|
|
400
400
|
const symbolName = args.symbolName.trim();
|
|
401
401
|
const topK = args.topK ?? 30;
|
|
402
402
|
try {
|
|
@@ -527,7 +527,7 @@ export function createRecallQuirksTool(options) {
|
|
|
527
527
|
quirkType: tool.schema.string().optional(),
|
|
528
528
|
tags: tool.schema.array(tool.schema.string().min(1)).max(10).optional(),
|
|
529
529
|
},
|
|
530
|
-
async execute(args) {
|
|
530
|
+
async execute(args, _context) {
|
|
531
531
|
try {
|
|
532
532
|
const deps = { embedder, store, keywordIndex, cfg, storePath };
|
|
533
533
|
const results = await recallQuirks(deps, args.query, {
|
|
@@ -599,7 +599,7 @@ export function createAddQuirkTool(options) {
|
|
|
599
599
|
tags: tool.schema.array(tool.schema.string().min(1)).max(10).optional(),
|
|
600
600
|
sourceRef: tool.schema.string().optional(),
|
|
601
601
|
},
|
|
602
|
-
async execute(args) {
|
|
602
|
+
async execute(args, _context) {
|
|
603
603
|
try {
|
|
604
604
|
const deps = { embedder, store, keywordIndex, cfg, storePath };
|
|
605
605
|
const quirk = await addQuirk(deps, {
|
|
@@ -655,7 +655,7 @@ export function createUpdateQuirkTool(options) {
|
|
|
655
655
|
confidence: tool.schema.number().min(0).max(1).optional(),
|
|
656
656
|
sourceRef: tool.schema.string().optional(),
|
|
657
657
|
},
|
|
658
|
-
async execute(args) {
|
|
658
|
+
async execute(args, _context) {
|
|
659
659
|
try {
|
|
660
660
|
const deps = { embedder, store, keywordIndex, cfg, storePath };
|
|
661
661
|
const fields = [
|
|
@@ -722,7 +722,7 @@ export function createDeleteQuirkTool(options) {
|
|
|
722
722
|
args: {
|
|
723
723
|
id: tool.schema.string().min(1, "Quirk ID is required."),
|
|
724
724
|
},
|
|
725
|
-
async execute(args) {
|
|
725
|
+
async execute(args, _context) {
|
|
726
726
|
try {
|
|
727
727
|
const deps = { embedder, store, keywordIndex, cfg, storePath };
|
|
728
728
|
await removeQuirk(deps, args.id);
|
package/dist/plugin-entry.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview OpenCode plugin entry point.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode V2 entrypoint: default export `Plugin.define({ id, setup })` —
|
|
5
|
+
* `setup(ctx)` registers the RAG tools/hooks through the V2 context adapter
|
|
6
|
+
* and returns a cleanup function for plugin unload. OpenCode 1.x support has
|
|
7
|
+
* been dropped (v2.0.0); the V1 `ragPlugin` factory remains the single source
|
|
8
|
+
* of truth for RAG logic (config, store, embedder, indexer, auto-update) and is
|
|
9
|
+
* re-registered as V2 transforms/hooks by src/v2/v2-adapter.ts.
|
|
4
10
|
*/
|
|
11
|
+
import { Plugin } from "@opencode/plugin";
|
|
5
12
|
/** Unique identifier for the OpenCodeRAG plugin. */
|
|
6
13
|
export declare const id = "opencode-rag-plugin";
|
|
7
|
-
|
|
8
|
-
export declare const server: import("@opencode-ai/plugin").Plugin;
|
|
9
|
-
/**
|
|
10
|
-
* Default export conforming to OpenCode's plugin module signature.
|
|
11
|
-
* OpenCode discovers plugins by importing this default export.
|
|
12
|
-
*/
|
|
13
|
-
declare const _default: {
|
|
14
|
-
id: string;
|
|
15
|
-
server: import("@opencode-ai/plugin").Plugin;
|
|
16
|
-
};
|
|
14
|
+
declare const _default: Plugin.Plugin;
|
|
17
15
|
export default _default;
|
package/dist/plugin-entry.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview OpenCode plugin entry point.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode V2 entrypoint: default export `Plugin.define({ id, setup })` —
|
|
5
|
+
* `setup(ctx)` registers the RAG tools/hooks through the V2 context adapter
|
|
6
|
+
* and returns a cleanup function for plugin unload. OpenCode 1.x support has
|
|
7
|
+
* been dropped (v2.0.0); the V1 `ragPlugin` factory remains the single source
|
|
8
|
+
* of truth for RAG logic (config, store, embedder, indexer, auto-update) and is
|
|
9
|
+
* re-registered as V2 transforms/hooks by src/v2/v2-adapter.ts.
|
|
4
10
|
*/
|
|
5
|
-
import {
|
|
11
|
+
import { Plugin } from "@opencode/plugin";
|
|
12
|
+
import { registerRagPluginV2 } from "./v2/v2-adapter.js";
|
|
6
13
|
/** Unique identifier for the OpenCodeRAG plugin. */
|
|
7
14
|
export const id = "opencode-rag-plugin";
|
|
8
|
-
/** Plugin server hooks — the ragPlugin factory registered with OpenCode's plugin system. */
|
|
9
|
-
export const server = ragPlugin;
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
16
|
+
* V2 `setup`: run the V1 factory for this location and re-register the
|
|
17
|
+
* returned hooks as V2 transforms/hooks. Returns a cleanup function for
|
|
18
|
+
* plugin unload.
|
|
13
19
|
*/
|
|
14
|
-
|
|
20
|
+
async function setup(ctx) {
|
|
21
|
+
return registerRagPluginV2(ctx);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Default export. `Plugin.define` is the documented V2 entrypoint (identity —
|
|
25
|
+
* it returns the object unchanged).
|
|
26
|
+
*/
|
|
27
|
+
const definition = { id, setup };
|
|
28
|
+
export default Plugin.define(definition);
|
|
15
29
|
//# sourceMappingURL=plugin-entry.js.map
|
package/dist/plugin.js
CHANGED
|
@@ -474,7 +474,7 @@ export function createRagHooks(options) {
|
|
|
474
474
|
topK: tool.schema.number().int().min(1).max(25).optional(),
|
|
475
475
|
explain: tool.schema.boolean().optional(),
|
|
476
476
|
},
|
|
477
|
-
async execute(args) {
|
|
477
|
+
async execute(args, _context) {
|
|
478
478
|
try {
|
|
479
479
|
const count = await store.count();
|
|
480
480
|
if (count === 0) {
|
|
@@ -839,7 +839,7 @@ export function createRagHooks(options) {
|
|
|
839
839
|
const budgetMs = memCfg.autoInjectLatencyBudgetMs ?? 2000;
|
|
840
840
|
let timer;
|
|
841
841
|
let quirkResults = await Promise.race([
|
|
842
|
-
recallQuirks(quirkDeps, query, { topK: memCfg.autoInjectTopK ??
|
|
842
|
+
recallQuirks(quirkDeps, query, { topK: memCfg.autoInjectTopK ?? 1, minScore: memCfg.autoInjectMinScore })
|
|
843
843
|
.then((r) => {
|
|
844
844
|
if (timer)
|
|
845
845
|
clearTimeout(timer);
|
|
@@ -855,7 +855,7 @@ export function createRagHooks(options) {
|
|
|
855
855
|
// Lexical gate: drop quirks that match only the prior assistant text (no token
|
|
856
856
|
// overlap with the user's actual request) — prevents meta-quirks (quirks about
|
|
857
857
|
// quirks) from being injected into unrelated tasks. Disabled when autoInjectMinTokenOverlap=0.
|
|
858
|
-
const minTokenOverlap = memCfg.autoInjectMinTokenOverlap ??
|
|
858
|
+
const minTokenOverlap = memCfg.autoInjectMinTokenOverlap ?? 2;
|
|
859
859
|
if (minTokenOverlap > 0 && userReq.length > 0) {
|
|
860
860
|
quirkResults = quirkResults.filter((qr) => sharedWords(qr.chunk.content, userReq) >= minTokenOverlap);
|
|
861
861
|
}
|
|
@@ -1140,12 +1140,14 @@ export function createRagHooks(options) {
|
|
|
1140
1140
|
if (quirkQuery.length > 0) {
|
|
1141
1141
|
const quirkDeps = { embedder, store, keywordIndex: keywordIndex, cfg: getEffectiveCfg(), storePath: options.storePath };
|
|
1142
1142
|
const budgetMs = quirkMemoryCfg.autoInjectLatencyBudgetMs ?? 2000;
|
|
1143
|
-
//
|
|
1144
|
-
//
|
|
1145
|
-
|
|
1143
|
+
// Both auto-inject paths (system prompt transform and this user-message
|
|
1144
|
+
// injection) use the same high autoInjectMinScore bar — injected quirks
|
|
1145
|
+
// occupy context every turn, so only strongly relevant ones qualify.
|
|
1146
|
+
// Manual recall_quirks calls use the lower recallMinScore.
|
|
1147
|
+
const minScore = quirkMemoryCfg.autoInjectMinScore ?? 0.75;
|
|
1146
1148
|
let timer;
|
|
1147
1149
|
let quirkResults = await Promise.race([
|
|
1148
|
-
recallQuirks(quirkDeps, quirkQuery, { topK: quirkMemoryCfg.autoInjectTopK ??
|
|
1150
|
+
recallQuirks(quirkDeps, quirkQuery, { topK: quirkMemoryCfg.autoInjectTopK ?? 1, minScore })
|
|
1149
1151
|
.then((r) => {
|
|
1150
1152
|
if (timer)
|
|
1151
1153
|
clearTimeout(timer);
|
|
@@ -1161,7 +1163,7 @@ export function createRagHooks(options) {
|
|
|
1161
1163
|
// Lexical gate: drop quirks that match only the prior assistant text (no token
|
|
1162
1164
|
// overlap with the user's current message) — prevents meta-quirks (quirks about
|
|
1163
1165
|
// quirks) from being injected into unrelated tasks. Disabled when autoInjectMinTokenOverlap=0.
|
|
1164
|
-
const minTokenOverlap = quirkMemoryCfg.autoInjectMinTokenOverlap ??
|
|
1166
|
+
const minTokenOverlap = quirkMemoryCfg.autoInjectMinTokenOverlap ?? 2;
|
|
1165
1167
|
if (minTokenOverlap > 0 && text.length > 0) {
|
|
1166
1168
|
quirkResults = quirkResults.filter((qr) => sharedWords(qr.chunk.content, text) >= minTokenOverlap);
|
|
1167
1169
|
}
|