opencode-rag-plugin 2.10.1 → 2.11.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.
- package/ReadMe.md +40 -28
- package/dist/api.js +1 -0
- package/dist/chunker/grammar.d.ts +4 -1
- package/dist/chunker/grammar.js +9 -3
- package/dist/chunker/skeleton.js +61 -4
- package/dist/cli/commands/clickhouse.d.ts +61 -0
- package/dist/cli/commands/clickhouse.js +335 -0
- package/dist/cli/commands/eval-tuner.js +1 -1
- package/dist/cli/commands/eval.js +1 -1
- package/dist/cli/commands/index-command.js +2 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/init-helpers.js +2 -2
- package/dist/cli/commands/init.js +49 -11
- package/dist/cli/commands/quirk.js +6 -6
- package/dist/cli/commands/status.js +70 -6
- package/dist/cli/commands/ui.js +2 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/types.d.ts +14 -0
- package/dist/core/bootstrap.d.ts +7 -0
- package/dist/core/bootstrap.js +40 -9
- package/dist/core/config.d.ts +128 -5
- package/dist/core/config.js +205 -8
- package/dist/core/interfaces.d.ts +54 -0
- package/dist/core/runtime-overrides.d.ts +9 -0
- package/dist/core/runtime-overrides.js +44 -0
- package/dist/core/state-sync.d.ts +91 -0
- package/dist/core/state-sync.js +273 -0
- package/dist/eval/fast-index.js +2 -2
- package/dist/eval/rerank-eval.js +2 -2
- package/dist/eval/run-branch-compare.js +2 -2
- package/dist/eval/run-token-test.js +2 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/indexer/pipeline.d.ts +6 -0
- package/dist/indexer/pipeline.js +173 -56
- package/dist/indexer/progress.d.ts +75 -0
- package/dist/indexer/progress.js +114 -0
- package/dist/indexer/stats.d.ts +14 -0
- package/dist/plugin.d.ts +6 -3
- package/dist/plugin.js +39 -20
- package/dist/quirks/quirk-store.d.ts +10 -0
- package/dist/quirks/quirk-store.js +110 -15
- package/dist/quirks/types.d.ts +7 -0
- package/dist/tui.js +128 -111
- package/dist/vectorstore/clickhouse.d.ts +150 -0
- package/dist/vectorstore/clickhouse.js +931 -0
- package/dist/vectorstore/dimension.d.ts +19 -0
- package/dist/vectorstore/dimension.js +36 -0
- package/dist/vectorstore/factory.d.ts +9 -3
- package/dist/vectorstore/factory.js +11 -2
- package/dist/vectorstore/lancedb.d.ts +2 -2
- package/dist/watcher.d.ts +29 -0
- package/dist/watcher.js +76 -2
- package/dist/web/api.d.ts +3 -4
- package/dist/web/api.js +18 -3
- package/dist/web/server.js +28 -2
- package/dist/web/ui/assets/{ScatterPlot3D-CKwyh1Ec.js → ScatterPlot3D-XjXIwavM.js} +5 -5
- package/dist/web/ui/assets/index-B-RH6fko.css +2 -0
- package/dist/web/ui/assets/index-FFPRbgLx.js +4 -0
- package/dist/web/ui/index.html +2 -2
- package/package.json +7 -2
- package/dist/web/ui/assets/index-CWcp0jNf.css +0 -2
- package/dist/web/ui/assets/index-DbXFrn53.js +0 -4
package/ReadMe.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenCodeRAG
|
|
2
2
|
|
|
3
|
-
OpenCodeRAG is a **local-first RAG plugin** for semantic code and image search, with a built-in **local decision model** for fast classification. It converts your codebase into vector indices and retrieves relevant code chunks on natural language queries. The primary aim is to save tokens by replacing full-file reads with targeted chunk retrieval and to speed-up tool calls for large codebases. Integrates seamlessly with [OpenCode](https://opencode.ai) and works as a standalone MCP server or CLI tool for other AI harnesses.
|
|
3
|
+
OpenCodeRAG is a **local-first RAG plugin** for semantic code and image search, with a built-in **local decision model** for fast classification and an optional **Shell Guard** that vets shell commands before they run. It converts your codebase into vector indices and retrieves relevant code chunks on natural language queries. The primary aim is to save tokens by replacing full-file reads with targeted chunk retrieval and to speed-up tool calls for large codebases. Integrates seamlessly with [OpenCode](https://opencode.ai) and works as a standalone MCP server or CLI tool for other AI harnesses.
|
|
4
4
|
|
|
5
5
|
You don't need a dedicated GPU to run smaller embedding LLMs, as these models can still run performant on modern CPUs.
|
|
6
6
|
|
|
@@ -8,6 +8,8 @@ You don't need a dedicated GPU to run smaller embedding LLMs, as these models ca
|
|
|
8
8
|
|
|
9
9
|
> ⚠️ **Note:** Don't confuse this with the npm package `opencode-rag` (a discontinued project by a different author).
|
|
10
10
|
|
|
11
|
+
> 🛡️ **Shell Guard (optional):** every `shell`/`bash` command is classified by the local decision model **before it runs**. Flagged commands ask for confirmation with the full verdict (`destructive`/`malicious` probabilities + risk category); clean commands run unchanged. Enable once, machine-wide — see [Shell Guard](#shell-guard-optional).
|
|
12
|
+
|
|
11
13
|
## Quick Start
|
|
12
14
|
|
|
13
15
|
```bash
|
|
@@ -23,11 +25,18 @@ opencode-rag index
|
|
|
23
25
|
|
|
24
26
|
# 4. CLI search test
|
|
25
27
|
opencode-rag query "authentication middleware"
|
|
28
|
+
|
|
29
|
+
# 5. Optional: vet every shell command (once per machine)
|
|
30
|
+
mkdir -p ~/.config/opencode
|
|
31
|
+
echo '{ "shellGuard": { "enabled": true } }' > ~/.config/opencode/opencode-rag.json
|
|
32
|
+
# Requires the decision model: ollama pull tev1:0.8b
|
|
26
33
|
```
|
|
27
34
|
|
|
35
|
+
> **Try it:** with Shell Guard enabled, `rm -rf ./dist` is flagged (`delete_files`, ~0.96 destructive) and prompts for confirmation, while `ls -la src` passes untouched (~0.2).
|
|
36
|
+
|
|
28
37
|
`opencode-rag setup` installs/verifies the machine-level runtime and, when
|
|
29
38
|
run inside a project, initializes the workspace (`.opencode/`, plugin entries,
|
|
30
|
-
skill file,
|
|
39
|
+
skill file, `.opencode/opencode-rag.json`) in one step. When the installed version is
|
|
31
40
|
outdated, it fetches and installs the latest published version from npm.
|
|
32
41
|
`opencode-rag init` remains available for re-syncing an already initialized
|
|
33
42
|
workspace, and `opencode-rag update` upgrades to a newer release.
|
|
@@ -42,6 +51,7 @@ workspace, and `opencode-rag update` upgrades to a newer release.
|
|
|
42
51
|
|
|
43
52
|
| Feature | Description |
|
|
44
53
|
|---|---|
|
|
54
|
+
| **🛡️ Shell guard** | Optional **pre-execution vetting of every `shell`/`bash` command** by the local decision model — flagged commands ask for confirmation (with probabilities + risk category), clean commands run normally, fail-open by default. Machine-wide via the global config. [Details](#shell-guard-optional) |
|
|
45
55
|
| **MCP server** | `opencode-rag mcp` - stdio-based MCP server exposing `search_semantic`, `get_file_skeleton`, `find_usages`, and `describe_image` tools for any MCP-compatible client |
|
|
46
56
|
| **AST chunking** | 26 languages via tree-sitter (TS, JS, Python, Java, Go, Rust, C/C++, C#, Ruby, Kotlin, Swift, Bash, PHP, PowerShell, SQL, JSON, HTML, CSS, XML (including SVG), YAML, TOML, INI, Dockerfile, Markdown, LaTeX, Razor) |
|
|
47
57
|
| **Configurable parsers** | Remap file extensions to any parser via `chunking.parsers` (e.g. `.c` → `cpp`, or index a new `.cu` as C++) — applied to chunking, `get_file_skeleton`, and read labels ([docs](doc/chunking.md#parser-overrides-per-extension-chunkingparsers)) |
|
|
@@ -50,11 +60,11 @@ workspace, and `opencode-rag update` upgrades to a newer release.
|
|
|
50
60
|
| **Hybrid search** | Vector similarity + TF×IDF keyword fusion — the keyword index is repaired from the store whenever it drifts behind it, so the BM25 half never covers only part of the corpus |
|
|
51
61
|
| **Retrieval calibration** | `opencode-rag eval:tune` sweeps the fusion weights against the labelled golden set and reports (or writes) the best configuration for your embedder and corpus |
|
|
52
62
|
| **Decision model** | Local [tev1](https://ollama.com/library/tev1) classification — `make_decision` labels, routes, and scores short text with probabilities (40–150 ms warm); optional pre-ask routing so the agent asks fewer questions |
|
|
53
|
-
| **Shell guard** | Optional pre-execution vetting of every `shell`/`bash` command by the local decision model — flagged commands ask for confirmation, clean ones run normally (fail-open by default) |
|
|
54
63
|
| **OpenCode plugin** | Auto-inject context, read-tool override, TUI settings, Ctrl+Enter to add RAG context, MCP registration on `init` |
|
|
55
64
|
| **Incremental indexing** | File-hash manifest, background watcher, auto-rebuild on corruption |
|
|
65
|
+
| **Central vector store** | Optional ClickHouse backend (`vectorStore.provider: "clickhouse"`) — one shared index for many machines/workspaces with HNSW ANN, epoch rebuilds and state sync; `opencode-rag clickhouse setup` configures it ([docs](doc/clickhouse.md)) |
|
|
56
66
|
| **Privacy-first** | All processing stays local (when using Ollama) |
|
|
57
|
-
| **CLI Tools** | `init`, `index`, `query`, `status`, `list`, `show`, `dump`, `clear`, `describe-image`, `decide`, `ui`, `mcp`, `setup`, `quirk`, `eval:sessions`, `eval:analyze`, `eval:compare`, `eval:gate`, `eval:decide`, `eval:tune` |
|
|
67
|
+
| **CLI Tools** | `init`, `index`, `query`, `status`, `list`, `show`, `dump`, `clear`, `describe-image`, `decide`, `ui`, `mcp`, `setup`, `clickhouse`, `quirk`, `eval:sessions`, `eval:analyze`, `eval:compare`, `eval:gate`, `eval:decide`, `eval:tune` |
|
|
58
68
|
| **Proxy-aware** | Corporate proxy support with raw-socket localhost bypass |
|
|
59
69
|
| **OpenAI / Anthropic / Cohere** | Use alternate embedding providers with API key auto-resolution |
|
|
60
70
|
| **Evaluation** | Session-level token tracking, RAG-on vs RAG-off comparison, tiktoken BPE counting |
|
|
@@ -64,6 +74,31 @@ workspace, and `opencode-rag update` upgrades to a newer release.
|
|
|
64
74
|
| **Quirk memory** | Persistent experiential memory — agents recall/persist gotchas, preferences, decisions across sessions (`add_quirk` / `recall_quirks`, `opencode-rag quirk`); failed tool calls are auto-recorded as quirks |
|
|
65
75
|
| **AGENTS.md directive** | `opencode-rag init` merges a tool-usage directive into `AGENTS.md` via sentinel markers |
|
|
66
76
|
|
|
77
|
+
## Shell Guard (Optional)
|
|
78
|
+
|
|
79
|
+
The same local decision model can vet **every shell command before it runs**. With `shellGuard.enabled: true`, each `shell`/`bash` call is classified for destructive and malicious intent; a command whose `p(destructive)` or `p(malicious)` reaches the threshold is escalated to OpenCode's confirmation prompt with the full verdict — otherwise it executes unchanged.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"shellGuard": {
|
|
84
|
+
"enabled": true,
|
|
85
|
+
"threshold": 0.5,
|
|
86
|
+
"timeoutMs": 10000,
|
|
87
|
+
"onError": "allow"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- **Off by default** — enabling adds one local model call to the critical path of every shell command.
|
|
93
|
+
- **Fast** — a warm verdict costs ~200–230 ms (`rm -rf ./dist` → 0.96 destructive, `delete_files`; `ls -la src` → 0.23, allowed). Repeated identical commands hit the 10-minute cache.
|
|
94
|
+
- **Machine-wide** — put the block in `~/.config/opencode/opencode-rag.json` (the global layer, see [Configuration](doc/configuration.md#config-file-discovery)) and every workspace inherits it; a workspace config can still override or disable it.
|
|
95
|
+
- **Fail-open by default** (`onError: "allow"`): if the classifier is down or times out, the command runs and a warning is logged. Set `onError: "ask"` to require confirmation instead.
|
|
96
|
+
- **Verdict cache** (10 min, 256 entries): repeated identical commands are answered instantly; the key includes the provider/model, so switching models invalidates it, and cached probabilities are re-scored against the current threshold on every call.
|
|
97
|
+
- **Config edits apply without a restart** — the guard re-reads `opencode-rag.json` when it changes.
|
|
98
|
+
- **Backend** defaults to the `decision` section, and any `/v1/systemone` endpoint works — e.g. llama-swap with `"baseUrl": "http://localhost:11437", "model": "Clef-Flash"`.
|
|
99
|
+
|
|
100
|
+
Every verdict is logged under `scope: shell.guard`, so you can tune the threshold against real commands. See [Configuration](doc/configuration.md#shellguard) and [Plugin documentation](doc/plugin.md#shell-guard-command-vetting).
|
|
101
|
+
|
|
67
102
|
## Web UI
|
|
68
103
|
|
|
69
104
|
A browser-based dashboard for exploring the indexed vector database - browse, visualize and inspect chunks and evaluate the OpenCode sessions in terms of retrieved chunks, consumed tokens and more.
|
|
@@ -81,6 +116,7 @@ Launch with `opencode-rag ui`. See [Web UI documentation](doc/webui.md) for deta
|
|
|
81
116
|
| [Configuration](doc/configuration.md) | All options: embedding, indexing, retrieval, description, image description, decision, shell guard, plugin |
|
|
82
117
|
| [Chunking](doc/chunking.md) | Language matrix, adding new chunkers, custom chunkers |
|
|
83
118
|
| [Embedding](doc/embedding.md) | Providers, model recommendations, proxy, dimension probing |
|
|
119
|
+
| [ClickHouse store](doc/clickhouse.md) | Central vector store backend: setup, epochs, ANN, multi-machine sync |
|
|
84
120
|
| [Retrieval](doc/retrieval.md) | Pipeline, hybrid search, score fusion, caching |
|
|
85
121
|
| [Plugin](doc/plugin.md) | OpenCode integration, tools, hooks, TUI, troubleshooting |
|
|
86
122
|
| [CLI Reference](doc/cli.md) | All commands, options, examples |
|
|
@@ -147,30 +183,6 @@ ollama pull tev1:4b # 4.4 GB, more accurate — recommended when scoring
|
|
|
147
183
|
|
|
148
184
|
`opencode-rag decide` exposes the same engine from the CLI, and `init` creates a dedicated `make-decision` agent skill. See [Plugin documentation](doc/plugin.md#make_decision) and [Configuration](doc/configuration.md#decision).
|
|
149
185
|
|
|
150
|
-
## Shell Guard (Optional)
|
|
151
|
-
|
|
152
|
-
The same local decision model can vet **every shell command before it runs**. With `shellGuard.enabled: true`, each `shell`/`bash` call is classified for destructive and malicious intent; a command whose `p(destructive)` or `p(malicious)` reaches the threshold is escalated to OpenCode's confirmation prompt with the full verdict — otherwise it executes unchanged.
|
|
153
|
-
|
|
154
|
-
```json
|
|
155
|
-
{
|
|
156
|
-
"shellGuard": {
|
|
157
|
-
"enabled": true,
|
|
158
|
-
"threshold": 0.5,
|
|
159
|
-
"timeoutMs": 10000,
|
|
160
|
-
"onError": "allow"
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
- **Off by default** — enabling adds one local model call to the critical path of every shell command.
|
|
166
|
-
- **Machine-wide** — put the block in `~/.config/opencode/opencode-rag.json` (the global layer, see [Configuration](doc/configuration.md#config-file-discovery)) and every workspace inherits it; a workspace config can still override or disable it.
|
|
167
|
-
- **Fail-open by default** (`onError: "allow"`): if the classifier is down or times out, the command runs and a warning is logged. Set `onError: "ask"` to require confirmation instead.
|
|
168
|
-
- **Verdict cache** (10 min, 256 entries): repeated identical commands are answered instantly; the key includes the provider/model, so switching models invalidates it, and cached probabilities are re-scored against the current threshold on every call.
|
|
169
|
-
- **Config edits apply without a restart** — the guard re-reads `opencode-rag.json` when it changes.
|
|
170
|
-
- **Backend** defaults to the `decision` section, and any `/v1/systemone` endpoint works — e.g. llama-swap with `"baseUrl": "http://localhost:11437", "model": "Clef-Flash"`.
|
|
171
|
-
|
|
172
|
-
Every verdict is logged under `scope: shell.guard`, so you can tune the threshold against real commands. See [Configuration](doc/configuration.md#shellguard) and [Plugin documentation](doc/plugin.md#shell-guard-command-vetting).
|
|
173
|
-
|
|
174
186
|
## Image Indexing
|
|
175
187
|
|
|
176
188
|
OpenCodeRAG can index image files (PNG, JPEG, WebP, etc.) by sending them to a vision-capable LLM and storing the generated text descriptions as searchable vector chunks. This makes visual assets discoverable via natural language queries (e.g., "login screen screenshot", "architecture diagram").
|
package/dist/api.js
CHANGED
|
@@ -90,6 +90,9 @@ export declare function buildByteOffsetMap(source: string): Map<number, number>
|
|
|
90
90
|
* @param source - Full source text (used to slice node text and comments).
|
|
91
91
|
* @param maxDepth - Maximum recursion depth (default: 10).
|
|
92
92
|
* @param depth - Current recursion depth (internal, start at 0).
|
|
93
|
+
* @param descend - When true, keep walking into a matched node's children so
|
|
94
|
+
* nested members are returned too. The chunker keeps the default (false) so
|
|
95
|
+
* one matched declaration stays one chunk; the skeleton outline opts in.
|
|
93
96
|
* @returns An array of {@link AstNode} objects for matching declarations.
|
|
94
97
|
*/
|
|
95
|
-
export declare function walkTree(node: Node, nodeTypes: Set<string>, source: string, maxDepth?: number, depth?: number, offsetMap?: Map<number, number> | null): AstNode[];
|
|
98
|
+
export declare function walkTree(node: Node, nodeTypes: Set<string>, source: string, maxDepth?: number, depth?: number, offsetMap?: Map<number, number> | null, descend?: boolean): AstNode[];
|
package/dist/chunker/grammar.js
CHANGED
|
@@ -249,9 +249,12 @@ function extractDocstringFromBody(node, source, offsetMap) {
|
|
|
249
249
|
* @param source - Full source text (used to slice node text and comments).
|
|
250
250
|
* @param maxDepth - Maximum recursion depth (default: 10).
|
|
251
251
|
* @param depth - Current recursion depth (internal, start at 0).
|
|
252
|
+
* @param descend - When true, keep walking into a matched node's children so
|
|
253
|
+
* nested members are returned too. The chunker keeps the default (false) so
|
|
254
|
+
* one matched declaration stays one chunk; the skeleton outline opts in.
|
|
252
255
|
* @returns An array of {@link AstNode} objects for matching declarations.
|
|
253
256
|
*/
|
|
254
|
-
export function walkTree(node, nodeTypes, source, maxDepth = 10, depth = 0, offsetMap) {
|
|
257
|
+
export function walkTree(node, nodeTypes, source, maxDepth = 10, depth = 0, offsetMap, descend = false) {
|
|
255
258
|
const results = [];
|
|
256
259
|
if (nodeTypes.has(node.type) && depth > 0) {
|
|
257
260
|
const leadingComments = extractLeadingComments(node, source, offsetMap);
|
|
@@ -268,11 +271,14 @@ export function walkTree(node, nodeTypes, source, maxDepth = 10, depth = 0, offs
|
|
|
268
271
|
type: node.type,
|
|
269
272
|
leadingDoc: leadingDoc.length > 0 ? leadingDoc : undefined,
|
|
270
273
|
});
|
|
271
|
-
|
|
274
|
+
// The chunker stops at the first matched declaration so that one
|
|
275
|
+
// declaration produces one chunk. The skeleton opts into descending.
|
|
276
|
+
if (!descend)
|
|
277
|
+
return results;
|
|
272
278
|
}
|
|
273
279
|
if (depth < maxDepth) {
|
|
274
280
|
for (const child of node.children) {
|
|
275
|
-
results.push(...walkTree(child, nodeTypes, source, maxDepth, depth + 1, offsetMap));
|
|
281
|
+
results.push(...walkTree(child, nodeTypes, source, maxDepth, depth + 1, offsetMap, descend));
|
|
276
282
|
}
|
|
277
283
|
}
|
|
278
284
|
return results;
|
package/dist/chunker/skeleton.js
CHANGED
|
@@ -21,16 +21,16 @@ export const SKELETON_CONFIGS = {
|
|
|
21
21
|
".jsx": { grammarName: "javascript", nodeTypes: ["function_declaration", "method_definition", "class_declaration", "arrow_function"] },
|
|
22
22
|
".mjs": { grammarName: "javascript", nodeTypes: ["function_declaration", "method_definition", "class_declaration", "arrow_function"] },
|
|
23
23
|
".cjs": { grammarName: "javascript", nodeTypes: ["function_declaration", "method_definition", "class_declaration", "arrow_function"] },
|
|
24
|
-
".py": { grammarName: "python", nodeTypes: ["function_definition", "class_definition"
|
|
24
|
+
".py": { grammarName: "python", nodeTypes: ["function_definition", "class_definition"] },
|
|
25
25
|
".java": { grammarName: "java", nodeTypes: ["class_declaration", "method_declaration", "interface_declaration", "enum_declaration"] },
|
|
26
|
-
".go": { grammarName: "go", nodeTypes: ["function_declaration", "method_declaration", "
|
|
26
|
+
".go": { grammarName: "go", nodeTypes: ["function_declaration", "method_declaration", "type_spec", "type_alias"] },
|
|
27
27
|
".rs": { grammarName: "rust", nodeTypes: ["function_item", "struct_item", "enum_item", "impl_item", "trait_item", "type_item"] },
|
|
28
28
|
".c": { grammarName: "c", nodeTypes: ["function_definition", "struct_specifier", "enum_specifier"] },
|
|
29
29
|
".cpp": { grammarName: "cpp", nodeTypes: ["function_definition", "class_specifier", "struct_specifier", "enum_specifier"] },
|
|
30
30
|
".cxx": { grammarName: "cpp", nodeTypes: ["function_definition", "class_specifier", "struct_specifier", "enum_specifier"] },
|
|
31
31
|
".h": { grammarName: "cpp", nodeTypes: ["function_definition", "class_specifier", "struct_specifier", "enum_specifier"] },
|
|
32
32
|
".hpp": { grammarName: "cpp", nodeTypes: ["function_definition", "class_specifier", "struct_specifier", "enum_specifier"] },
|
|
33
|
-
".cs": { grammarName: "c_sharp", nodeTypes: ["class_declaration", "
|
|
33
|
+
".cs": { grammarName: "c_sharp", nodeTypes: ["class_declaration", "struct_declaration", "interface_declaration", "enum_declaration", "record_declaration", "delegate_declaration", "constructor_declaration", "destructor_declaration", "method_declaration", "property_declaration", "indexer_declaration", "event_field_declaration", "event_declaration", "operator_declaration", "conversion_operator_declaration"] },
|
|
34
34
|
".rb": { grammarName: "ruby", nodeTypes: ["method", "class", "module"] },
|
|
35
35
|
".swift": { grammarName: "swift", nodeTypes: ["function_declaration", "class_declaration", "struct_declaration", "enum_declaration", "protocol_declaration"] },
|
|
36
36
|
".kt": { grammarName: "kotlin", nodeTypes: ["function_declaration", "class_declaration", "interface_declaration", "object_declaration"] },
|
|
@@ -99,6 +99,61 @@ function resolveSkeletonKey(ext, overrides) {
|
|
|
99
99
|
// line-count fallback instead of using it.
|
|
100
100
|
return hit ?? NO_SKELETON;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Node types that represent executable bodies. A callable nested inside
|
|
104
|
+
* another callable is an implementation detail (callback, local helper), not
|
|
105
|
+
* a member of the file's outline, so descent drops it. A callable nested in a
|
|
106
|
+
* type (a method, constructor, …) is kept.
|
|
107
|
+
*/
|
|
108
|
+
const CALLABLE_NODE_TYPES = new Set([
|
|
109
|
+
"function_declaration",
|
|
110
|
+
"function_definition",
|
|
111
|
+
"function_item",
|
|
112
|
+
"function",
|
|
113
|
+
"method_declaration",
|
|
114
|
+
"method_definition",
|
|
115
|
+
"method",
|
|
116
|
+
"constructor_declaration",
|
|
117
|
+
"destructor_declaration",
|
|
118
|
+
"operator_declaration",
|
|
119
|
+
"conversion_operator_declaration",
|
|
120
|
+
"arrow_function",
|
|
121
|
+
"generator_function_declaration",
|
|
122
|
+
"generator_function",
|
|
123
|
+
"lambda",
|
|
124
|
+
"lambda_expression",
|
|
125
|
+
"lambda_literal",
|
|
126
|
+
"func_literal",
|
|
127
|
+
"closure_expression",
|
|
128
|
+
"anonymous_function",
|
|
129
|
+
]);
|
|
130
|
+
/**
|
|
131
|
+
* Drop a callable whose nearest outlined ancestor is also a callable, keeping
|
|
132
|
+
* the outer one. Types and their members are unaffected: only body-level
|
|
133
|
+
* nesting is removed, so a method of a local class still appears.
|
|
134
|
+
*/
|
|
135
|
+
function dropNestedCallables(nodes) {
|
|
136
|
+
return nodes.filter((node) => {
|
|
137
|
+
if (!CALLABLE_NODE_TYPES.has(node.type))
|
|
138
|
+
return true;
|
|
139
|
+
let nearest;
|
|
140
|
+
for (const other of nodes) {
|
|
141
|
+
if (other === node)
|
|
142
|
+
continue;
|
|
143
|
+
const contains = other.startIndex <= node.startIndex &&
|
|
144
|
+
other.endIndex >= node.endIndex &&
|
|
145
|
+
(other.startIndex < node.startIndex || other.endIndex > node.endIndex);
|
|
146
|
+
if (!contains)
|
|
147
|
+
continue;
|
|
148
|
+
if (!nearest ||
|
|
149
|
+
other.startIndex > nearest.startIndex ||
|
|
150
|
+
(other.startIndex === nearest.startIndex && other.endIndex < nearest.endIndex)) {
|
|
151
|
+
nearest = other;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return !nearest || !CALLABLE_NODE_TYPES.has(nearest.type);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
102
157
|
/**
|
|
103
158
|
* Extract structural outline from source code using tree-sitter.
|
|
104
159
|
* Falls back to regex patterns for languages without WASM grammars, and to a
|
|
@@ -150,7 +205,9 @@ export async function extractSkeleton(content, ext, options) {
|
|
|
150
205
|
return [];
|
|
151
206
|
try {
|
|
152
207
|
const nodeTypes = new Set(config.nodeTypes);
|
|
153
|
-
|
|
208
|
+
// Descend into matched declarations: a skeleton describes the members
|
|
209
|
+
// inside a type, whereas the chunker intentionally stops at the type.
|
|
210
|
+
const astNodes = dropNestedCallables(walkTree(tree.rootNode, nodeTypes, content, 15, 0, undefined, true));
|
|
154
211
|
return astNodes.map((node) => ({
|
|
155
212
|
type: node.type,
|
|
156
213
|
name: extractNodeName(node.text, node.type),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `clickhouse setup` — interactively configure and initialize the
|
|
3
|
+
* ClickHouse vector store.
|
|
4
|
+
*
|
|
5
|
+
* Prompts for the endpoint, port, database, credentials, namespace, embedding
|
|
6
|
+
* dimension and ANN mode; probes the server (version/auth), creates the
|
|
7
|
+
* database and the project tables, then writes the `vectorStore` block into the
|
|
8
|
+
* workspace or global config file. Existing config keys are preserved.
|
|
9
|
+
*/
|
|
10
|
+
import type { Command } from "commander";
|
|
11
|
+
import { createInterface } from "node:readline/promises";
|
|
12
|
+
/** Options for `opencode-rag clickhouse setup`. */
|
|
13
|
+
export interface ClickHouseSetupOptions {
|
|
14
|
+
url?: string;
|
|
15
|
+
port?: string;
|
|
16
|
+
database?: string;
|
|
17
|
+
username?: string;
|
|
18
|
+
password?: string;
|
|
19
|
+
passwordEnv?: string;
|
|
20
|
+
namespace?: string;
|
|
21
|
+
ann?: string;
|
|
22
|
+
dimension?: string;
|
|
23
|
+
scope?: string;
|
|
24
|
+
storePassword?: boolean;
|
|
25
|
+
skipInit?: boolean;
|
|
26
|
+
yes?: boolean;
|
|
27
|
+
/** Working directory override (tests); defaults to `process.cwd()`. */
|
|
28
|
+
cwd?: string;
|
|
29
|
+
}
|
|
30
|
+
interface SetupInput {
|
|
31
|
+
url: string;
|
|
32
|
+
database: string;
|
|
33
|
+
username: string;
|
|
34
|
+
password: string;
|
|
35
|
+
passwordEnv: string;
|
|
36
|
+
namespace: string;
|
|
37
|
+
ann: "off" | "hnsw";
|
|
38
|
+
dimension: number;
|
|
39
|
+
storeInlinePassword: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merge a ClickHouse `vectorStore` block into an existing config object.
|
|
43
|
+
* Exported for tests; preserves every unrelated top-level key and the old
|
|
44
|
+
* cache path when ClickHouse was already active.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mergeClickHouseConfig(existing: Record<string, unknown> | undefined, input: Pick<SetupInput, "url" | "database" | "username" | "password" | "passwordEnv" | "namespace" | "ann" | "storeInlinePassword">): Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Prompt for a password without echoing it.
|
|
49
|
+
*
|
|
50
|
+
* Readline's internal `_writeToOutput` hook is muted while the answer is read —
|
|
51
|
+
* an active readline interface otherwise echoes every keystroke, even when the
|
|
52
|
+
* caller switches the stream to raw mode.
|
|
53
|
+
*/
|
|
54
|
+
export declare function promptHidden(rl: ReturnType<typeof createInterface>, question: string): Promise<string>;
|
|
55
|
+
/** Compose `scheme://host:port` from a user-supplied URL and port. */
|
|
56
|
+
export declare function composeClickHouseUrl(rawUrl: string, port: string): string;
|
|
57
|
+
/** Run the interactive (or flag-driven) ClickHouse setup. */
|
|
58
|
+
export declare function runClickHouseSetup(options?: ClickHouseSetupOptions): Promise<void>;
|
|
59
|
+
/** Register the `clickhouse` command group. */
|
|
60
|
+
export declare function registerClickHouseCommand(program: Command): void;
|
|
61
|
+
export {};
|