opencode-rag-plugin 1.3.5 → 1.4.2
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/ReadMe.md +148 -418
- package/dist/chunker/pdf.js +25 -4
- package/dist/chunker/pdf.js.map +1 -1
- package/dist/cli.d.ts +0 -5
- package/dist/cli.js +245 -102
- package/dist/cli.js.map +1 -1
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +16 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/interfaces.d.ts +6 -1
- package/dist/core/manifest.d.ts +2 -0
- package/dist/core/manifest.js +5 -2
- package/dist/core/manifest.js.map +1 -1
- package/dist/core/runtime-overrides.d.ts +28 -0
- package/dist/core/runtime-overrides.js +83 -0
- package/dist/core/runtime-overrides.js.map +1 -0
- package/dist/describer/describer.d.ts +12 -0
- package/dist/describer/describer.js +177 -0
- package/dist/describer/describer.js.map +1 -0
- package/dist/describer/factory.d.ts +3 -0
- package/dist/describer/factory.js +5 -0
- package/dist/describer/factory.js.map +1 -0
- package/dist/embedder/factory.d.ts +1 -1
- package/dist/embedder/factory.js +2 -2
- package/dist/embedder/factory.js.map +1 -1
- package/dist/embedder/ollama.d.ts +1 -1
- package/dist/embedder/ollama.js +1 -1
- package/dist/embedder/ollama.js.map +1 -1
- package/dist/embedder/openai.d.ts +1 -1
- package/dist/embedder/openai.js +6 -2
- package/dist/embedder/openai.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +2 -1
- package/dist/indexer.js +36 -1
- package/dist/indexer.js.map +1 -1
- package/dist/opencode/create-read-tool.js +2 -2
- package/dist/opencode/create-read-tool.js.map +1 -1
- package/dist/plugin.d.ts +2 -1
- package/dist/plugin.js +42 -13
- package/dist/plugin.js.map +1 -1
- package/dist/retriever/retriever.d.ts +1 -0
- package/dist/retriever/retriever.js +2 -1
- package/dist/retriever/retriever.js.map +1 -1
- package/dist/tui.js +285 -11
- package/dist/tui.js.map +1 -1
- package/dist/vectorstore/lancedb.d.ts +19 -0
- package/dist/vectorstore/lancedb.js +162 -41
- package/dist/vectorstore/lancedb.js.map +1 -1
- package/dist/watcher.d.ts +6 -1
- package/dist/watcher.js +72 -26
- package/dist/watcher.js.map +1 -1
- package/package.json +3 -1
package/ReadMe.md
CHANGED
|
@@ -1,68 +1,40 @@
|
|
|
1
1
|
# OpenCodeRAG
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCodeRAG is a RAG (Retrieval-Augmented Generation) plugin for semantic code search powered by locally-hosted embedding models.
|
|
4
|
+
It features a seamless integration with [OpenCode](https://opencode.ai) and offers a CLI interface for external usage.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
[](https://www.npmjs.com/package/opencode-rag-plugin)
|
|
6
7
|
|
|
7
|
-
> ⚠️ **
|
|
8
|
+
> ⚠️ **Note:** Don't confuse this with the npm-package `opencode-rag`, which is a discontinued project of a different author. Ensure you are using **`opencode-rag-plugin`**.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
**Why Using OpenCodeRAG?**
|
|
11
|
+
OpenCodeRAG aims to reduce LLM token usage by replacing expensive full-file reads with targeted, vector-similarity-based chunk retrieval.
|
|
12
|
+
Large codebases benefit massively in performance. It runs perfectly on a local dedicated GPU, but modern CPUs handle most workloads just fine.
|
|
13
|
+
When using only locally hosted embedding models and LLMs, your codebase also remains 100% private.
|
|
10
14
|
|
|
11
15
|
---
|
|
12
16
|
|
|
13
17
|
## Table of Contents
|
|
14
18
|
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- [Configuration](#configuration)
|
|
24
|
-
- [Embedding Providers](#embedding-providers)
|
|
25
|
-
- [Logging](#logging)
|
|
26
|
-
- [Usage](#usage)
|
|
27
|
-
- [CLI](#cli)
|
|
28
|
-
- [OpenCode Plugin](#opencode-plugin)
|
|
29
|
-
- [Architecture](#architecture)
|
|
30
|
-
- [Tech Stack](#tech-stack)
|
|
31
|
-
- [Chunking Language Support](#chunking-language-support)
|
|
32
|
-
- [Adding Custom Chunkers](#adding-custom-chunkers)
|
|
33
|
-
- [Data Model](#data-model)
|
|
34
|
-
- [Vector Store](#vector-store)
|
|
35
|
-
- [Development](#development)
|
|
36
|
-
- [Privacy](#privacy)
|
|
19
|
+
- [Quick Start](#-quick-start)
|
|
20
|
+
- [How it Works](#-how-it-works)
|
|
21
|
+
- [OpenCode Integration](#-opencode-integration)
|
|
22
|
+
- [Configuration](#-configuration)
|
|
23
|
+
- [CLI Usage (Standalone)](#-cli-interface)
|
|
24
|
+
- [Supported Languages](#-supported-languages)
|
|
25
|
+
- [Developer Guide & Architecture](#-developer-guide--architecture)
|
|
26
|
+
- [Privacy & Security](#-privacy--security)
|
|
37
27
|
|
|
38
28
|
---
|
|
39
29
|
|
|
40
|
-
##
|
|
41
|
-
|
|
42
|
-
| Feature | Description |
|
|
43
|
-
|---------|-------------|
|
|
44
|
-
| **AST-aware chunking** | Splits code into functions, classes, and methods via tree-sitter for 16 languages; regex-based for Markdown, Razor, `.sln`, and LaTeX; line-based fallback for everything else |
|
|
45
|
-
| **Incremental indexing** | Skips unchanged files, removes deleted entries, re-indexes only what changed |
|
|
46
|
-
| **Watch mode** | `index --watch` debounces file changes and re-indexes automatically |
|
|
47
|
-
| **Pluggable chunkers** | Add custom language chunkers via config file or programmatic API |
|
|
48
|
-
| **Configurable embeddings** | Ollama (default, fully local) or any OpenAI-compatible provider; configurable batch size |
|
|
49
|
-
| **Hybrid search** | TF×IDF keyword index fused with vector similarity — better precision on identifiers and function names |
|
|
50
|
-
| **Local vector store** | LanceDB with L2 distance scoring; in-memory mode for testing |
|
|
51
|
-
| **CLI** | `index`, `query`, `clear`, `status` commands |
|
|
52
|
-
| **OpenCode integration** | Auto-injects relevant code chunks into each message; suggests related files; exposes a retrieval tool the agent can call directly |
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## Prerequisites
|
|
57
|
-
|
|
58
|
-
- **[OpenCode](https://opencode.ai)** installed and configured
|
|
59
|
-
- **Node.js v22+** (required for native ESM and `fetch`)
|
|
60
|
-
- **[Ollama](https://ollama.ai)** running locally with an embedding model (default: `nomic-embed-text`)
|
|
61
|
-
— or any OpenAI-compatible embedding API
|
|
30
|
+
## Quick Start
|
|
62
31
|
|
|
63
|
-
|
|
32
|
+
### Prerequisites
|
|
33
|
+
- **Node.js v22+** (required for native ESM and `fetch`).
|
|
34
|
+
- **[Ollama](https://ollama.ai)** running locally (default model: `embeddinggemma`) OR an OpenAI-compatible API.
|
|
35
|
+
- **[OpenCode](https://opencode.ai)** if you want to use the automated agent features.
|
|
64
36
|
|
|
65
|
-
|
|
37
|
+
### Installation
|
|
66
38
|
|
|
67
39
|
```bash
|
|
68
40
|
# 1. Clone the repository
|
|
@@ -73,258 +45,117 @@ cd OpenCodeRAG
|
|
|
73
45
|
./install.sh # Linux/macOS
|
|
74
46
|
.\install.ps1 # Windows
|
|
75
47
|
|
|
76
|
-
# 3.
|
|
48
|
+
# 3. Initialize in your project
|
|
77
49
|
cd /path/to/your/project
|
|
78
50
|
opencode-rag init
|
|
79
51
|
|
|
80
|
-
# 4.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# 5. Restart OpenCode — the plugin is active
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## Installation
|
|
89
|
-
|
|
90
|
-
### Global Installation (Recommended)
|
|
91
|
-
|
|
92
|
-
Clone the repository and run the platform-specific install script:
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
# Linux/macOS
|
|
96
|
-
./install.sh
|
|
97
|
-
|
|
98
|
-
# Windows
|
|
99
|
-
.\install.ps1
|
|
100
|
-
```
|
|
52
|
+
# 4. Edit configuration file (optional), e.g.
|
|
53
|
+
nano opencoderag.json
|
|
101
54
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
2. Install it into OpenCode's runtime (`~/.opencode/node_modules/`)
|
|
105
|
-
3. Register it in the global OpenCode config (`~/.config/opencode/opencode.jsonc`)
|
|
106
|
-
|
|
107
|
-
**Restart OpenCode after installation.**
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
### Per-Workspace Setup
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
cd your-workspace
|
|
115
|
-
opencode-rag init
|
|
55
|
+
# 4. Index your workspace
|
|
56
|
+
opencode-rag index
|
|
116
57
|
```
|
|
117
58
|
|
|
118
|
-
|
|
119
|
-
Add `--skip-install` to generate the files only, without installing dependencies.
|
|
59
|
+
*(To uninstall, simply run `./install.sh uninstall` or `.\install.ps1 uninstall`)*
|
|
120
60
|
|
|
121
61
|
---
|
|
122
62
|
|
|
123
|
-
|
|
63
|
+
## How it Works
|
|
124
64
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
# Install into OpenCode's runtime
|
|
132
|
-
npm install --prefix ~/.opencode/ opencode-rag-plugin-1.2.0.tgz
|
|
133
|
-
npm install --prefix ~/.config/opencode/ opencode-rag-plugin-1.2.0.tgz
|
|
134
|
-
|
|
135
|
-
# Then add "opencode-rag-plugin" to the plugins array in:
|
|
136
|
-
# ~/.config/opencode/opencode.jsonc
|
|
137
|
-
```
|
|
65
|
+
OpenCodeRAG intelligently processes your query in OpenCode and your codebase for high-precision retrieval:
|
|
66
|
+
1. **AST-aware chunking:** Intelligently splits code into functions, methods, and classes using `tree-sitter`.
|
|
67
|
+
2. **Local Vector Database:** Uses LanceDB to store embeddings locally without any cloud dependencies.
|
|
68
|
+
3. **Hybrid Search:** Combines TF×IDF keyword matching with vector similarity for superior precision on identifiers.
|
|
69
|
+
4. **Incremental Indexing:** Only updates files that have changed, ensuring that the vector database stays up-to-date.
|
|
138
70
|
|
|
139
71
|
---
|
|
140
72
|
|
|
141
|
-
|
|
73
|
+
## OpenCode Integration
|
|
142
74
|
|
|
143
|
-
|
|
144
|
-
# Linux/macOS
|
|
145
|
-
./install.sh uninstall
|
|
75
|
+
When are using OpenCode, the plugin enhances your agent with two main features:
|
|
146
76
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
77
|
+
### 1. Auto-Injection (Background Context)
|
|
78
|
+
After every message you send, the plugin effectively searches your vector-indexed codebase:
|
|
79
|
+
- **High-confidence results (score ≥ 0.75):** Actual code chunks are injected directly into your prompt, giving the agent instant context without a tool-call round-trip.
|
|
80
|
+
- **Lower-confidence results:** A compact list of suggested files is appended instead (e.g., `src/plugin.ts (lines 10-42)`).
|
|
150
81
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
> **Automatic dependencies:** `apache-arrow` (LanceDB peer dependency) and `tree-sitter-wasm` (pre-built WASM grammars) are installed automatically.
|
|
82
|
+
### 2. Direct Tool Call (`opencode-rag-context`)
|
|
83
|
+
Any OpenCode agent can actively invoke the RAG tool to fetch specific code chunks, filter by exact file paths, or target specific programming languages.
|
|
154
84
|
|
|
155
85
|
---
|
|
156
86
|
|
|
157
87
|
## Configuration
|
|
158
88
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
The repository's own [`opencode-rag.json`](./opencode-rag.json) is a complete, annotated example covering all available options.
|
|
162
|
-
|
|
163
|
-
**Partial overrides are supported:** only the keys you set are applied — everything else falls back to defaults. Sections are deep-merged.
|
|
164
|
-
|
|
165
|
-
---
|
|
89
|
+
Running `opencode-rag init` creates the config file `opencode-rag.json` in your project root. You only need to define the values you want to override.
|
|
166
90
|
|
|
167
91
|
### Embedding Providers
|
|
168
|
-
|
|
169
|
-
| Provider | `baseUrl` | Notes |
|
|
170
|
-
|----------|-----------|-------|
|
|
171
|
-
| `ollama` | `http://localhost:11434/api` | **Default.** No API key required. |
|
|
172
|
-
| `openai` | `https://api.openai.com/v1` | Requires `apiKey`. Sends all texts in one batch request. |
|
|
173
|
-
|
|
174
|
-
- `embedding.timeoutMs` defaults to `30000` ms. Increase it if your local model has a slow cold start.
|
|
175
|
-
- Ollama sends one request per batch to `/api/embed`. Set `embedding.proxy.url` to route through a standard HTTP proxy.
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
### Logging
|
|
180
|
-
|
|
181
92
|
```json
|
|
182
93
|
{
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
94
|
+
"embedding": {
|
|
95
|
+
"provider": "ollama",
|
|
96
|
+
"baseUrl": "http://localhost:11434/api",
|
|
97
|
+
"timeoutMs": 30000
|
|
186
98
|
}
|
|
187
99
|
}
|
|
188
100
|
```
|
|
101
|
+
* **Ollama (Default):** Local, private, no API key needed. *(Increase `timeoutMs` if your model has a slow cold start)*.
|
|
102
|
+
* **OpenAI:** Set `provider` to `"openai"`, change `baseUrl` to `"https://api.openai.com/v1"`, and provide your `apiKey`.
|
|
103
|
+
|
|
104
|
+
### Plugin Settings
|
|
189
105
|
|
|
190
106
|
| Option | Default | Description |
|
|
191
107
|
|--------|---------|-------------|
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
108
|
+
| `openCode.readOverride` | `false` | If `true`, overrides OpenCode's default file reader to append RAG chunks as supplementary context. |
|
|
109
|
+
| `openCode.autoInject.enabled` | `true` | Turn background auto-injection on/off. |
|
|
110
|
+
| `openCode.autoInject.minScore` | `0.75` | Minimum relevance score to inject actual code (0–1). |
|
|
111
|
+
| `retrieval.topK` | `10` | Default number of chunks fetched per query. |
|
|
112
|
+
| `retrieval.hybridSearch.enabled` | `true` | Enables combined TF×IDF + vector search. |
|
|
194
113
|
|
|
195
|
-
|
|
114
|
+
### Description-Based Embedding (Optional)
|
|
196
115
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
## Usage
|
|
200
|
-
|
|
201
|
-
OpenCodeRAG provides two interfaces:
|
|
202
|
-
|
|
203
|
-
| Interface | Best for |
|
|
204
|
-
|-----------|----------|
|
|
205
|
-
| **CLI** | Manual indexing, searching, and diagnostics |
|
|
206
|
-
| **OpenCode plugin** | Automatic retrieval and file suggestions while chatting |
|
|
207
|
-
|
|
208
|
-
---
|
|
209
|
-
|
|
210
|
-
### CLI
|
|
116
|
+
When enabled, the indexer uses an LLM to generate natural-language descriptions of code chunks, then combines the description with the raw code for embedding. This captures both semantic meaning (from the description) and code-level similarity (from the code itself), dramatically improving search quality for natural language and code-based queries alike.
|
|
211
117
|
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
opencode-rag query "How is authentication handled?"
|
|
224
|
-
opencode-rag query "error handling" --top-k 5
|
|
225
|
-
|
|
226
|
-
# Show index statistics
|
|
227
|
-
opencode-rag status
|
|
228
|
-
|
|
229
|
-
# Clear all indexed data
|
|
230
|
-
opencode-rag clear
|
|
231
|
-
|
|
232
|
-
# Use a custom config file
|
|
233
|
-
opencode-rag index --config ./my-config.json
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
**Example `status` output:**
|
|
237
|
-
```
|
|
238
|
-
Indexed chunks: 1247
|
|
239
|
-
Store path: /home/user/project/.opencode/rag_db
|
|
240
|
-
Embedding provider: ollama
|
|
241
|
-
Embedding model: nomic-embed-text
|
|
242
|
-
Manifest status: ok
|
|
243
|
-
Manifest entries: 42
|
|
244
|
-
Last indexed: 2026-05-28 10:45:02
|
|
245
|
-
Up-to-date files: 42
|
|
246
|
-
Pending files: 0
|
|
247
|
-
Keyword index: enabled (1274 chunks)
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"description": {
|
|
121
|
+
"enabled": true,
|
|
122
|
+
"provider": "ollama",
|
|
123
|
+
"baseUrl": "http://localhost:11434/api",
|
|
124
|
+
"model": "qwen2.5:3b",
|
|
125
|
+
"timeoutMs": 60000,
|
|
126
|
+
"systemPrompt": "You are a code analysis assistant. Given a code snippet, write a short (2-3 sentence) description of what the code does, its purpose, and key functionality. Focus on semantic meaning that would help someone searching for this code. Do not include code in your response."
|
|
127
|
+
}
|
|
128
|
+
}
|
|
248
129
|
```
|
|
249
130
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
131
|
+
| Option | Default | Description |
|
|
132
|
+
|--------|---------|-------------|
|
|
133
|
+
| `description.enabled` | `true` | Enable description-based embedding. Set to `false` to embed raw code instead. |
|
|
134
|
+
| `description.provider` | `"ollama"` | LLM provider (`"ollama"` or `"openai"`). |
|
|
135
|
+
| `description.model` | `"qwen2.5:3b"` | Model name for description generation. |
|
|
136
|
+
| `description.systemPrompt` | *(see above)* | Customizable system prompt for the LLM. |
|
|
137
|
+
| `description.timeoutMs` | `60000` | Timeout per LLM call. |
|
|
253
138
|
|
|
254
|
-
|
|
255
|
-
- If the manifest is missing or corrupt while the store already has data, the next pass **clears and rebuilds** the entire store to prevent duplicates.
|
|
139
|
+
The embedded text is formed as `description + "\n\n" + code content`. The description and code are still stored as separate fields in LanceDB. Keyword search continues to use the raw code content. Set `description.enabled` to `false` to disable and embed raw code content instead. If the LLM call fails during indexing, the chunk falls back to embedding raw content with a warning logged.
|
|
256
140
|
|
|
257
|
-
|
|
141
|
+
<details>
|
|
142
|
+
<summary>View Logging Configuration</summary>
|
|
258
143
|
|
|
259
|
-
```
|
|
260
|
-
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"logging": {
|
|
147
|
+
"level": "info", // Options: "debug", "info", or "error"
|
|
148
|
+
"logFilePath": "./.opencode/opencode-rag.log"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
261
151
|
```
|
|
152
|
+
</details>
|
|
262
153
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
- If a pass is already running, one follow-up pass is queued and starts immediately after.
|
|
266
|
-
- The watcher ignores excluded directories, the vector store path, and the manifest file itself.
|
|
267
|
-
- Press `Ctrl+C` to stop.
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
### OpenCode Plugin
|
|
272
|
-
|
|
273
|
-
Once installed, the plugin registers two hooks:
|
|
274
|
-
|
|
275
|
-
| Hook | What it does |
|
|
276
|
-
|------|-------------|
|
|
277
|
-
| `opencode-rag-context` | A retrieval tool the agent can call directly to fetch code chunks with file paths and line ranges |
|
|
278
|
-
| `chat.message` | After each user message, retrieves relevant files and appends them to the message |
|
|
279
|
-
|
|
280
|
-
#### Auto-Injection
|
|
154
|
+
### `AGENTS.md` Setup
|
|
155
|
+
To ensure the OpenCode agent knows how to leverage the plugin, add this snippet to your workspace's `AGENTS.md`:
|
|
281
156
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
1. Extracts your message text
|
|
285
|
-
2. Runs semantic retrieval against the indexed workspace
|
|
286
|
-
3. **High-confidence results** (relevance ≥ `autoInject.minScore`, default `0.75`): injects the actual code chunks directly into the message — the agent gets context without a tool-call round-trip:
|
|
287
|
-
```
|
|
288
|
-
---
|
|
289
|
-
**Auto-retrieved code context** _(context: 2 chunks, 1 file, relevance 0.88–0.92)_
|
|
290
|
-
---
|
|
291
|
-
[src/auth.ts:12-30] (typescript, score: 0.92)
|
|
292
|
-
```typescript
|
|
293
|
-
function login() { ... }
|
|
294
|
-
```
|
|
295
|
-
---
|
|
296
|
-
```
|
|
297
|
-
4. **No high-confidence results**: falls back to a compact file list (max 10 files):
|
|
298
|
-
```
|
|
299
|
-
src/plugin.ts (typescript, lines 10-42, relevance 0.87)
|
|
300
|
-
src/core/config.ts (typescript, lines 66-145, relevance 0.72)
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
This eliminates a tool-call round-trip for roughly 70% of code-related messages. The agent can still call `opencode-rag-context` for more targeted or additional context.
|
|
304
|
-
|
|
305
|
-
> **Note:** Retrieval errors are silently caught — a failed search will never break the chat.
|
|
306
|
-
|
|
307
|
-
---
|
|
308
|
-
|
|
309
|
-
#### Plugin Configuration Reference
|
|
310
|
-
|
|
311
|
-
| Option | Default | Description |
|
|
312
|
-
|--------|---------|-------------|
|
|
313
|
-
| `openCode.readOverride` | `false` | When `true`, registers a RAG-backed `read` tool that shadows OpenCode's built-in file reader — returns full file contents with relevant RAG chunks appended as supplementary context |
|
|
314
|
-
| `openCode.maxContextChunks` | `5` | Maximum chunks returned by `opencode-rag-context` |
|
|
315
|
-
| `openCode.autoInject.enabled` | `true` | Enable or disable auto-injection |
|
|
316
|
-
| `openCode.autoInject.minScore` | `0.75` | Minimum relevance score for auto-injection (0–1) |
|
|
317
|
-
| `openCode.autoInject.maxChunks` | `3` | Maximum chunks to inject per message |
|
|
318
|
-
| `openCode.autoInject.maxTokens` | `2000` | Token budget for injected content (~4 chars/token) |
|
|
319
|
-
| `retrieval.topK` | `10` | Chunks fetched per query (controls file suggestion breadth) |
|
|
320
|
-
| `retrieval.hybridSearch.enabled` | `true` | Enable or disable hybrid TF×IDF + vector search |
|
|
321
|
-
| `retrieval.hybridSearch.keywordWeight` | `0.4` | Keyword weight in hybrid fusion (0–1; higher = more keyword influence) |
|
|
322
|
-
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
#### AGENTS.md Snippet
|
|
326
|
-
|
|
327
|
-
Add this section to your workspace's `AGENTS.md` so the agent knows how to use the plugin:
|
|
157
|
+
<details>
|
|
158
|
+
<summary>Click to view the AGENTS.md snippet</summary>
|
|
328
159
|
|
|
329
160
|
```markdown
|
|
330
161
|
## OpenCodeRAG Plugin
|
|
@@ -332,198 +163,97 @@ Add this section to your workspace's `AGENTS.md` so the agent knows how to use t
|
|
|
332
163
|
This workspace has OpenCodeRAG installed for semantic code retrieval.
|
|
333
164
|
|
|
334
165
|
### `opencode-rag-context` tool
|
|
335
|
-
Before planning, editing, or answering questions, use this tool to retrieve relevant
|
|
336
|
-
code chunks with file paths, line ranges, and surrounding implementation.
|
|
166
|
+
Before planning, editing, or answering questions, use this tool to retrieve relevant code chunks with file paths, line ranges, and surrounding implementation.
|
|
337
167
|
- `query` (required) — narrow, specific search, e.g. `"authentication middleware setup"`
|
|
338
168
|
- `pathHints` (optional) — up to 10 path filters, e.g. `["src/auth/"]`
|
|
339
169
|
- `languageHints` (optional) — up to 10 language filters, e.g. `["typescript"]`
|
|
340
170
|
- `topK` (optional) — result count (1–25, default 10)
|
|
341
171
|
|
|
342
172
|
### File suggestions
|
|
343
|
-
After each user message, a `chat.message` hook appends up to 10 relevant file
|
|
344
|
-
suggestions. Look for lines like `src/file.ts (typescript, lines 10-42)` at the
|
|
345
|
-
bottom of user input.
|
|
173
|
+
After each user message, a `chat.message` hook appends up to 10 relevant file suggestions. Look for lines like `src/file.ts (typescript, lines 10-42)` at the bottom of user input.
|
|
346
174
|
|
|
347
175
|
### Indexing
|
|
348
|
-
- Changed files are auto-indexed in the background
|
|
349
|
-
- If searches return no results,
|
|
350
|
-
run `opencode-rag index` from the terminal (or `npx opencode-rag-plugin`).
|
|
351
|
-
- Files under 1 KB, excluded extensions, and excluded directories
|
|
352
|
-
(`node_modules`, `.git`, `.opencode`, `dist`, etc.) are silently skipped.
|
|
176
|
+
- Changed files are auto-indexed in the background.
|
|
177
|
+
- If searches return no results, run `opencode-rag index` in the terminal.
|
|
353
178
|
```
|
|
354
|
-
|
|
355
|
-
The plugin also injects a reminder about `opencode-rag-context` into the agent's system prompt via `experimental.chat.system.transform`.
|
|
179
|
+
</details>
|
|
356
180
|
|
|
357
181
|
---
|
|
358
182
|
|
|
359
|
-
##
|
|
183
|
+
## CLI Interface
|
|
360
184
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
│
|
|
364
|
-
▼
|
|
365
|
-
┌──────────────┐
|
|
366
|
-
│ Chunker │ AST-based (tree-sitter) or line-based fallback
|
|
367
|
-
└──────┬───────┘
|
|
368
|
-
│ chunks
|
|
369
|
-
▼
|
|
370
|
-
┌──────────────┐
|
|
371
|
-
│ Embedder │ Ollama / OpenAI-compatible API
|
|
372
|
-
└──────┬───────┘
|
|
373
|
-
│ vectors
|
|
374
|
-
▼
|
|
375
|
-
┌──────────────┐
|
|
376
|
-
│ VectorStore │ LanceDB (local files or memory:// for tests)
|
|
377
|
-
└──────┬───────┘
|
|
378
|
-
│ + manifest.json
|
|
379
|
-
▼
|
|
380
|
-
┌──────────────┐
|
|
381
|
-
│ Indexer/Retr.│ incremental index or query/search
|
|
382
|
-
└──────┬───────┘
|
|
383
|
-
│ results
|
|
384
|
-
▼
|
|
385
|
-
LLM Context
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
---
|
|
389
|
-
|
|
390
|
-
## Tech Stack
|
|
391
|
-
|
|
392
|
-
| Layer | Technology |
|
|
393
|
-
|-------|------------|
|
|
394
|
-
| Runtime | Node.js v22 + tsx (ESM) |
|
|
395
|
-
| Language | TypeScript 5.8 |
|
|
396
|
-
| Chunking | web-tree-sitter (WASM) + tree-sitter-wasm grammars |
|
|
397
|
-
| Embeddings | Ollama / OpenAI-compatible (native fetch) |
|
|
398
|
-
| Vector DB | LanceDB (`@lancedb/lancedb`) |
|
|
399
|
-
| CLI | commander |
|
|
400
|
-
| Tests | Node built-in test runner (`node --test`) |
|
|
401
|
-
| Package manager | npm (with `--legacy-peer-deps`) |
|
|
185
|
+
The CLI interface (`opencode-rag`) provides full access to build, manage, and search your project's vector database, even without using OpenCode.
|
|
186
|
+
This is mainly intended for testing/debugging purposes, but can also be integrated into your own applications or scripts.
|
|
402
187
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
| Language | Strategy | Captures |
|
|
408
|
-
|----------|----------|---------|
|
|
409
|
-
| TypeScript | AST (tree-sitter) | functions, methods, classes, interfaces |
|
|
410
|
-
| JavaScript | AST (tree-sitter) | functions, classes, arrow functions, exports |
|
|
411
|
-
| Python | AST (tree-sitter) | functions, classes, decorated definitions |
|
|
412
|
-
| Java | AST (tree-sitter) | methods, classes, interfaces, enums |
|
|
413
|
-
| Go | AST (tree-sitter) | functions, methods, type declarations |
|
|
414
|
-
| Rust | AST (tree-sitter) | functions, structs, enums, traits, impl blocks, modules, types |
|
|
415
|
-
| C | AST (tree-sitter) | functions, structs, enums, unions, typedefs |
|
|
416
|
-
| C++ | AST (tree-sitter) | functions, classes, structs, enums, namespaces, templates |
|
|
417
|
-
| C# | AST (tree-sitter) | classes, interfaces, structs, enums, methods, namespaces, records |
|
|
418
|
-
| Ruby | AST (tree-sitter) | methods, classes, modules, singleton methods |
|
|
419
|
-
| Kotlin | AST (tree-sitter) | functions, classes, interfaces, objects, properties |
|
|
420
|
-
| Swift | AST (tree-sitter) | functions, classes, structs, enums, protocols, extensions, variables |
|
|
421
|
-
| JSON | AST (tree-sitter) | key-value pairs |
|
|
422
|
-
| XML | AST (tree-sitter) | elements (1 chunk per root element) |
|
|
423
|
-
| HTML | AST (tree-sitter) | `<script>` / `<style>` blocks |
|
|
424
|
-
| CSS | AST (tree-sitter) | rule sets, at-rules, media, keyframes |
|
|
425
|
-
| Razor | Regex (brace matching) | `@code` / `@functions` blocks, template regions |
|
|
426
|
-
| Markdown | Regex heading split | h1/h2 sections + trailing content |
|
|
427
|
-
| Solution (`.sln`) | Regex (section boundary) | project entries and global sections |
|
|
428
|
-
| LaTeX | Regex section split | chapter/section/subsection/subsubsection boundaries |
|
|
429
|
-
| PDF | Paragraph-based | groups small paragraphs, splits oversized ones |
|
|
430
|
-
| Word (`.docx`) | Paragraph-based | extracts via mammoth; groups small paragraphs, splits oversized |
|
|
431
|
-
| Word (`.doc`) | Paragraph-based | extracts via word-extractor; groups small paragraphs, splits oversized |
|
|
432
|
-
| Excel (`.xls`/`.xlsx`) | Row-batch | extracts CSV per sheet via `@e965/xlsx`; splits by sheet, then by row batch |
|
|
433
|
-
| *(other)* | Line-based (100 lines/chunk) | raw text blocks |
|
|
434
|
-
|
|
435
|
-
### Adding Custom Chunkers
|
|
436
|
-
|
|
437
|
-
Custom chunkers can be registered without modifying the project source.
|
|
438
|
-
|
|
439
|
-
**Via config file** — add to `opencode-rag.json`:
|
|
188
|
+
```bash
|
|
189
|
+
# Index the workspace (incremental by default)
|
|
190
|
+
opencode-rag index
|
|
440
191
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
"chunkers": [
|
|
444
|
-
{ "module": "./path/to/my-chunker.js", "extensions": [".xyz"] }
|
|
445
|
-
]
|
|
446
|
-
}
|
|
447
|
-
```
|
|
192
|
+
# Watch for file changes and re-index automatically
|
|
193
|
+
opencode-rag index --watch
|
|
448
194
|
|
|
449
|
-
|
|
195
|
+
# Force a complete rebuild of the index
|
|
196
|
+
opencode-rag index --force
|
|
450
197
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
readonly language: string;
|
|
454
|
-
readonly fileExtensions?: string[];
|
|
455
|
-
chunk(filePath: string, content: string): Promise<Chunk[]>;
|
|
456
|
-
}
|
|
457
|
-
```
|
|
198
|
+
# Semantic search directly from the terminal
|
|
199
|
+
opencode-rag query "How is authentication handled?" --top-k 5
|
|
458
200
|
|
|
459
|
-
|
|
201
|
+
# Show index statistics or clear data
|
|
202
|
+
opencode-rag status
|
|
203
|
+
opencode-rag clear
|
|
460
204
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
205
|
+
# Inspect indexed data
|
|
206
|
+
opencode-rag list # list all indexed files with chunk counts
|
|
207
|
+
opencode-rag show src/auth.ts # show chunks for a specific file
|
|
208
|
+
opencode-rag dump --limit 50 # dump all chunks (paginated)
|
|
464
209
|
```
|
|
465
210
|
|
|
466
|
-
> If a built-in chunker already handles the requested extension, the new registration is skipped and a warning is emitted.
|
|
467
|
-
|
|
468
211
|
---
|
|
469
212
|
|
|
470
|
-
##
|
|
471
|
-
|
|
472
|
-
```typescript
|
|
473
|
-
interface Chunk {
|
|
474
|
-
id: string;
|
|
475
|
-
content: string;
|
|
476
|
-
embedding?: number[];
|
|
477
|
-
metadata: {
|
|
478
|
-
filePath: string;
|
|
479
|
-
startLine: number;
|
|
480
|
-
endLine: number;
|
|
481
|
-
language: string;
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
interface SearchResult {
|
|
486
|
-
chunk: Chunk;
|
|
487
|
-
score: number; // 1 / (1 + L2_distance), range [0, 1]
|
|
488
|
-
}
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
---
|
|
213
|
+
## Supported Languages
|
|
492
214
|
|
|
493
|
-
|
|
215
|
+
OpenCodeRAG uses advanced AST (Abstract Syntax Tree) parsing via `tree-sitter` for major languages, falling back to regex or line-based chunking for others.
|
|
494
216
|
|
|
495
|
-
|
|
217
|
+
* **AST Support:** TypeScript, JavaScript, Python, Java, Go, Rust, C, C++, C#, Ruby, Kotlin, Swift, JSON, XML, HTML, CSS.
|
|
218
|
+
* **Regex / Structure Support:** Markdown, Razor, `.sln`, LaTeX, PDF, Word (`.docx`/`.doc`), Excel.
|
|
219
|
+
* **Fallback:** Raw text blocks (100 lines/chunk).
|
|
496
220
|
|
|
497
|
-
|
|
498
|
-
|------|-------------|
|
|
499
|
-
| **Disk** | Files written to `vectorStore.path` (default: `.opencode/rag_db`) |
|
|
500
|
-
| **Memory** | `memory://` URI — for tests only; data is lost when the process exits |
|
|
221
|
+
---
|
|
501
222
|
|
|
502
|
-
|
|
503
|
-
- Schema is auto-inferred from a seed row on first table creation
|
|
504
|
-
- L2 distance search; score = `1 / (1 + distance)`
|
|
505
|
-
- File paths are normalized to absolute forward-slash paths
|
|
506
|
-
- `manifest.json` in the store directory tracks indexed files for incremental updates
|
|
223
|
+
## Developer Guide
|
|
507
224
|
|
|
508
|
-
|
|
225
|
+
Developers are welcome! If you fixed a bug or implemented a new feature, just submit your pull request to this repository.
|
|
509
226
|
|
|
510
|
-
|
|
227
|
+
### Architecture Flow
|
|
228
|
+
```text
|
|
229
|
+
Workspace Files ──> Chunker (tree-sitter/regex) ──> Chunks
|
|
230
|
+
│
|
|
231
|
+
Chunks ──> Embedder (Ollama/OpenAI) ──> Vectors
|
|
232
|
+
│
|
|
233
|
+
Vectors ──> VectorStore (LanceDB) <──> Indexer / Retriever ──> CLI / Agent Context
|
|
234
|
+
```
|
|
511
235
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
236
|
+
### Tech Stack
|
|
237
|
+
- **Runtime:** Node.js v22 + `tsx` (ESM), TypeScript 5.8
|
|
238
|
+
- **Chunking:** `web-tree-sitter` (WASM) + grammars
|
|
239
|
+
- **Vector DB:** LanceDB (`@lancedb/lancedb`) stored locally (`.opencode/rag_db`)
|
|
240
|
+
- **Tests:** Node built-in test runner (`npm test`)
|
|
515
241
|
|
|
516
|
-
# Run all tests
|
|
517
|
-
npm test
|
|
518
242
|
|
|
519
|
-
|
|
520
|
-
|
|
243
|
+
### Adding Custom Chunkers
|
|
244
|
+
You can easily inject custom chunkers without modifying the source code via `opencode-rag.json`:
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"chunkers": [
|
|
248
|
+
{ "module": "./path/to/my-chunker.js", "extensions": [".xyz"] }
|
|
249
|
+
]
|
|
250
|
+
}
|
|
521
251
|
```
|
|
522
252
|
|
|
523
|
-
Tests use Node's built-in runner (`node:test`) with `tsx` for TypeScript imports. No external test library is required.
|
|
524
|
-
|
|
525
253
|
---
|
|
526
254
|
|
|
527
|
-
## Privacy
|
|
255
|
+
## Privacy & Security
|
|
256
|
+
|
|
257
|
+
**100% Local Processing by Default.**
|
|
258
|
+
Whether you use it via CLI or as an agent plugin, OpenCodeRAG honors privacy strictly. Embeddings are generated locally by Ollama, and the vector database (LanceDB) is stored right in your project's directory. **No source code or embeddings ever leave your machine** unless you explicitly configure a third-party API like OpenAI.
|
|
528
259
|
|
|
529
|
-
All processing runs locally. By default, embeddings are generated by Ollama on your own machine. **No data leaves your machine** unless you configure a remote embedding API.
|