ragcode-context-engine 0.1.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/LICENSE +21 -0
- package/README.md +366 -0
- package/README.zh-CN.md +363 -0
- package/dist/src/cli/configure/app.d.ts +6 -0
- package/dist/src/cli/configure/app.js +81 -0
- package/dist/src/cli/configure/run.d.ts +5 -0
- package/dist/src/cli/configure/run.js +85 -0
- package/dist/src/cli/configure/state.d.ts +42 -0
- package/dist/src/cli/configure/state.js +174 -0
- package/dist/src/cli/configure.d.ts +31 -0
- package/dist/src/cli/configure.js +101 -0
- package/dist/src/cli/index.d.ts +2 -0
- package/dist/src/cli/index.js +503 -0
- package/dist/src/cli/tui/index-progress.d.ts +12 -0
- package/dist/src/cli/tui/index-progress.js +49 -0
- package/dist/src/cli/tui/watch-status.d.ts +10 -0
- package/dist/src/cli/tui/watch-status.js +27 -0
- package/dist/src/cli/update.d.ts +18 -0
- package/dist/src/cli/update.js +111 -0
- package/dist/src/config/dotenv.d.ts +1 -0
- package/dist/src/config/dotenv.js +14 -0
- package/dist/src/config/graph-runtime.d.ts +13 -0
- package/dist/src/config/graph-runtime.js +29 -0
- package/dist/src/config/runtime-config.d.ts +87 -0
- package/dist/src/config/runtime-config.js +215 -0
- package/dist/src/config/semantic-runtime.d.ts +24 -0
- package/dist/src/config/semantic-runtime.js +89 -0
- package/dist/src/context/context-builder.d.ts +20 -0
- package/dist/src/context/context-builder.js +277 -0
- package/dist/src/context/expansion-policy.d.ts +6 -0
- package/dist/src/context/expansion-policy.js +49 -0
- package/dist/src/context/skeletonizer.d.ts +2 -0
- package/dist/src/context/skeletonizer.js +79 -0
- package/dist/src/context/snippet-renderer.d.ts +2 -0
- package/dist/src/context/snippet-renderer.js +67 -0
- package/dist/src/core/contracts.d.ts +74 -0
- package/dist/src/core/contracts.js +1 -0
- package/dist/src/core/engine.d.ts +64 -0
- package/dist/src/core/engine.js +442 -0
- package/dist/src/core/types.d.ts +490 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/diagnostics/doctor.d.ts +66 -0
- package/dist/src/diagnostics/doctor.js +193 -0
- package/dist/src/diagnostics/embedding-test.d.ts +24 -0
- package/dist/src/diagnostics/embedding-test.js +83 -0
- package/dist/src/graph/diff-files.d.ts +1 -0
- package/dist/src/graph/diff-files.js +14 -0
- package/dist/src/graph/impact-report.d.ts +10 -0
- package/dist/src/graph/impact-report.js +173 -0
- package/dist/src/graph/in-memory-graph-store.d.ts +36 -0
- package/dist/src/graph/in-memory-graph-store.js +395 -0
- package/dist/src/graph/owner-ranking.d.ts +2 -0
- package/dist/src/graph/owner-ranking.js +41 -0
- package/dist/src/graph/sqlite-graph-store.d.ts +51 -0
- package/dist/src/graph/sqlite-graph-store.js +724 -0
- package/dist/src/graph/sqlite-statements.d.ts +36 -0
- package/dist/src/graph/sqlite-statements.js +105 -0
- package/dist/src/graph/target-matcher.d.ts +13 -0
- package/dist/src/graph/target-matcher.js +64 -0
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.js +32 -0
- package/dist/src/indexing/analyzers/fallback-analyzer.d.ts +6 -0
- package/dist/src/indexing/analyzers/fallback-analyzer.js +45 -0
- package/dist/src/indexing/analyzers/go-treesitter-analyzer.d.ts +2 -0
- package/dist/src/indexing/analyzers/go-treesitter-analyzer.js +87 -0
- package/dist/src/indexing/analyzers/java-treesitter-analyzer.d.ts +2 -0
- package/dist/src/indexing/analyzers/java-treesitter-analyzer.js +88 -0
- package/dist/src/indexing/analyzers/python-treesitter-analyzer.d.ts +2 -0
- package/dist/src/indexing/analyzers/python-treesitter-analyzer.js +96 -0
- package/dist/src/indexing/analyzers/registry.d.ts +5 -0
- package/dist/src/indexing/analyzers/registry.js +23 -0
- package/dist/src/indexing/analyzers/rust-treesitter-analyzer.d.ts +2 -0
- package/dist/src/indexing/analyzers/rust-treesitter-analyzer.js +96 -0
- package/dist/src/indexing/analyzers/tree-sitter-base.d.ts +30 -0
- package/dist/src/indexing/analyzers/tree-sitter-base.js +163 -0
- package/dist/src/indexing/analyzers/types.d.ts +17 -0
- package/dist/src/indexing/analyzers/types.js +1 -0
- package/dist/src/indexing/analyzers/typescript-analyzer.d.ts +5 -0
- package/dist/src/indexing/analyzers/typescript-analyzer.js +199 -0
- package/dist/src/indexing/ast-analyzer.d.ts +11 -0
- package/dist/src/indexing/ast-analyzer.js +11 -0
- package/dist/src/indexing/chunker.d.ts +11 -0
- package/dist/src/indexing/chunker.js +157 -0
- package/dist/src/indexing/ignore-policy.d.ts +6 -0
- package/dist/src/indexing/ignore-policy.js +40 -0
- package/dist/src/indexing/indexer.d.ts +13 -0
- package/dist/src/indexing/indexer.js +189 -0
- package/dist/src/indexing/language.d.ts +3 -0
- package/dist/src/indexing/language.js +24 -0
- package/dist/src/indexing/scanner.d.ts +13 -0
- package/dist/src/indexing/scanner.js +87 -0
- package/dist/src/lsp/definition-resolver.d.ts +6 -0
- package/dist/src/lsp/definition-resolver.js +60 -0
- package/dist/src/lsp/typescript-language-service.d.ts +21 -0
- package/dist/src/lsp/typescript-language-service.js +82 -0
- package/dist/src/mcp/server.d.ts +11 -0
- package/dist/src/mcp/server.js +64 -0
- package/dist/src/mcp/tools.d.ts +266 -0
- package/dist/src/mcp/tools.js +309 -0
- package/dist/src/project/project-identity.d.ts +2 -0
- package/dist/src/project/project-identity.js +24 -0
- package/dist/src/project/project-registry.d.ts +12 -0
- package/dist/src/project/project-registry.js +49 -0
- package/dist/src/project/workspace-resolver.d.ts +20 -0
- package/dist/src/project/workspace-resolver.js +62 -0
- package/dist/src/retrieval/graph-reranker.d.ts +11 -0
- package/dist/src/retrieval/graph-reranker.js +0 -0
- package/dist/src/retrieval/hybrid-retriever.d.ts +31 -0
- package/dist/src/retrieval/hybrid-retriever.js +111 -0
- package/dist/src/retrieval/path-classification.d.ts +6 -0
- package/dist/src/retrieval/path-classification.js +22 -0
- package/dist/src/retrieval/query-matching.d.ts +22 -0
- package/dist/src/retrieval/query-matching.js +166 -0
- package/dist/src/retrieval/query-planner.d.ts +5 -0
- package/dist/src/retrieval/query-planner.js +77 -0
- package/dist/src/retrieval/ranking-signals.d.ts +19 -0
- package/dist/src/retrieval/ranking-signals.js +97 -0
- package/dist/src/retrieval/topology-distance.d.ts +21 -0
- package/dist/src/retrieval/topology-distance.js +116 -0
- package/dist/src/reuse/reuse-detector.d.ts +12 -0
- package/dist/src/reuse/reuse-detector.js +564 -0
- package/dist/src/semantic/deterministic-embedding.d.ts +7 -0
- package/dist/src/semantic/deterministic-embedding.js +31 -0
- package/dist/src/semantic/in-memory-semantic-store.d.ts +11 -0
- package/dist/src/semantic/in-memory-semantic-store.js +65 -0
- package/dist/src/semantic/lance-semantic-store.d.ts +131 -0
- package/dist/src/semantic/lance-semantic-store.js +623 -0
- package/dist/src/semantic/openai-compatible-embedding.d.ts +19 -0
- package/dist/src/semantic/openai-compatible-embedding.js +75 -0
- package/dist/src/service/service-identity.d.ts +13 -0
- package/dist/src/service/service-identity.js +48 -0
- package/dist/src/service/service-manager.d.ts +29 -0
- package/dist/src/service/service-manager.js +231 -0
- package/dist/src/service/service-templates.d.ts +22 -0
- package/dist/src/service/service-templates.js +101 -0
- package/dist/src/subgraph/impact-explainer.d.ts +2 -0
- package/dist/src/subgraph/impact-explainer.js +54 -0
- package/dist/src/subgraph/node-expander.d.ts +13 -0
- package/dist/src/subgraph/node-expander.js +139 -0
- package/dist/src/subgraph/output-preset.d.ts +3 -0
- package/dist/src/subgraph/output-preset.js +102 -0
- package/dist/src/subgraph/subgraph-builder.d.ts +17 -0
- package/dist/src/subgraph/subgraph-builder.js +688 -0
- package/dist/src/topology/export-index.d.ts +7 -0
- package/dist/src/topology/export-index.js +14 -0
- package/dist/src/topology/framework-topology.d.ts +3 -0
- package/dist/src/topology/framework-topology.js +460 -0
- package/dist/src/topology/import-resolver.d.ts +2 -0
- package/dist/src/topology/import-resolver.js +29 -0
- package/dist/src/topology/orm-topology.d.ts +3 -0
- package/dist/src/topology/orm-topology.js +200 -0
- package/dist/src/topology/runtime-topology.d.ts +3 -0
- package/dist/src/topology/runtime-topology.js +204 -0
- package/dist/src/topology/symbol-resolver.d.ts +6 -0
- package/dist/src/topology/symbol-resolver.js +74 -0
- package/dist/src/topology/test-topology.d.ts +2 -0
- package/dist/src/topology/test-topology.js +82 -0
- package/dist/src/utils/hash.d.ts +2 -0
- package/dist/src/utils/hash.js +7 -0
- package/dist/src/utils/path.d.ts +2 -0
- package/dist/src/utils/path.js +7 -0
- package/dist/src/watch/event-journal.d.ts +17 -0
- package/dist/src/watch/event-journal.js +81 -0
- package/dist/src/watch/file-event-coalescer.d.ts +9 -0
- package/dist/src/watch/file-event-coalescer.js +39 -0
- package/dist/src/watch/index-scheduler.d.ts +52 -0
- package/dist/src/watch/index-scheduler.js +190 -0
- package/dist/src/watch/watch-daemon.d.ts +73 -0
- package/dist/src/watch/watch-daemon.js +368 -0
- package/dist/src/watch/watcher-liveness.d.ts +47 -0
- package/dist/src/watch/watcher-liveness.js +168 -0
- package/dist/src/web/server.d.ts +1 -0
- package/dist/src/web/server.js +375 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RagCode Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/images/eeb4a920-7607-41a7-aa2c-1d897a96a1ee.png" alt="RagCode logo" width="180" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">RagCode Context Engine</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/MarshallEriksen-Neura/ragcode/actions/workflows/ci.yml"><img src="https://github.com/MarshallEriksen-Neura/ragcode/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/ragcode-context-engine"><img src="https://img.shields.io/npm/v/ragcode-context-engine.svg" alt="npm version" /></a>
|
|
10
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
|
|
11
|
+
<a href="https://nodejs.org/"><img src="https://img.shields.io/badge/node-%3E%3D24-green.svg" alt="Node >= 24" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center"><b>English</b> · <a href="./README.zh-CN.md">简体中文</a></p>
|
|
15
|
+
|
|
16
|
+
RagCode is a **fully-local, verified context layer for coding agents.**
|
|
17
|
+
|
|
18
|
+
Most code-intelligence tools *retrieve* — they hand an agent relevant snippets and stop there. RagCode goes one step further: it tells the agent **whether it has enough verified context to safely act**. Every answer carries explicit citations, freshness, ownership, blast-radius, coverage signals, and an `edit-readiness` verdict (`safe_to_edit_after_reading` / `investigate_only` / `not_enough_context`) — plus an honest record of what evidence is still missing.
|
|
19
|
+
|
|
20
|
+
It is **editor-agnostic and MCP-native** (Claude Code, Codex, or any MCP client — not locked to one editor) and runs **entirely on your machine** (no account, no API key, no code leaving the building). The first run works offline with deterministic embeddings; swap in an OpenAI-compatible provider only if and when you want better recall.
|
|
21
|
+
|
|
22
|
+
Under the hood it cleanly separates structural code indexing, semantic retrieval, context packing, and MCP integration so each layer evolves independently — building on ideas from projects like CodeGraph and Understand-Anything, with a LanceDB semantic layer and a stronger context-engine contract on top.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Why RagCode
|
|
27
|
+
|
|
28
|
+
| If you need… | RagCode fits because… |
|
|
29
|
+
|---|---|
|
|
30
|
+
| Context that isn't locked to one editor | MCP-native; works with any agent harness, not a single IDE |
|
|
31
|
+
| Code that never leaves your machine | Fully local index + offline embeddings; no cloud round-trip |
|
|
32
|
+
| Agents that act correctly, not just confidently | Verified subgraphs with coverage signals + `edit-readiness`, not raw snippet dumps |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Technology Stack
|
|
37
|
+
|
|
38
|
+
| Area | Technology |
|
|
39
|
+
|------|-----------|
|
|
40
|
+
| Language / Runtime | TypeScript 5.9, Node.js **>= 24** (uses `node:sqlite`), ESM modules |
|
|
41
|
+
| Structural graph | `better-sqlite3` (SQLite + FTS) with an in-memory store for tests |
|
|
42
|
+
| Semantic / vector store | `@lancedb/lancedb` + `apache-arrow`, with an in-memory store fallback |
|
|
43
|
+
| AST / parsing | TypeScript Compiler API (TS/JS), `tree-sitter` (Python, Go, Rust, Java) |
|
|
44
|
+
| MCP integration | `@modelcontextprotocol/sdk` (stdio server) |
|
|
45
|
+
| CLI | `commander`, `ink` + `react` (interactive wizards) |
|
|
46
|
+
| Web dashboard | `express` + `ws` backend, Vue frontend (in `web/`) |
|
|
47
|
+
| File watching | `chokidar` |
|
|
48
|
+
| Validation | `zod` |
|
|
49
|
+
| Tooling | `tsx` (dev), `vitest` (tests), `tsc` (build + type check) |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Project Architecture
|
|
54
|
+
|
|
55
|
+
RagCode is layered so that no concrete store leaks across boundaries. Every external surface (CLI, MCP, web) depends on the contracts in `src/core`, never on a specific database.
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
┌──────────┐ ┌──────────┐ ┌──────────────┐
|
|
59
|
+
surfaces │ CLI │ │ MCP │ │ Web dashboard │
|
|
60
|
+
└────┬─────┘ └────┬─────┘ └──────┬───────┘
|
|
61
|
+
└──────────────┴────────────────┘
|
|
62
|
+
│
|
|
63
|
+
┌───────────▼───────────┐
|
|
64
|
+
│ ContextEngine (core) │ canonical contracts
|
|
65
|
+
└───────────┬───────────┘
|
|
66
|
+
┌──────────────┬────────┼────────┬──────────────┐
|
|
67
|
+
▼ ▼ ▼ ▼ ▼
|
|
68
|
+
┌────────┐ ┌─────────┐ ┌──────┐ ┌─────────┐ ┌─────────┐
|
|
69
|
+
│indexing│ │ graph │ │ sem. │ │retrieval│ │ context │
|
|
70
|
+
│ scan │ │ SQLite │ │Lance │ │ planner │ │ packer │
|
|
71
|
+
│ chunk │ │ +FTS │ │ DB │ │ +fusion │ │ +budget │
|
|
72
|
+
└────────┘ └─────────┘ └──────┘ └─────────┘ └─────────┘
|
|
73
|
+
│
|
|
74
|
+
┌─────▼─────┐
|
|
75
|
+
│ watch │ incremental freshness
|
|
76
|
+
└───────────┘
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Layer ownership** (see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)):
|
|
80
|
+
|
|
81
|
+
- **core** — canonical contracts: `RepoIndex`, `CodeFile`, `CodeChunk`, `GraphStore`, `SemanticStore`, `ContextEngine`. The stable boundary everything else depends on.
|
|
82
|
+
- **indexing** — filesystem scan, ignore rules, hashing, chunking, and index-pipeline steps. Knows nothing about MCP.
|
|
83
|
+
- **graph** — exact code structure: files, symbols, edges, lookup, callers/callees/impact. In-memory for tests, SQLite + FTS for production.
|
|
84
|
+
- **semantic** — embeddings and vector search behind an interface, so providers (deterministic, OpenAI-compatible, local) and stores swap freely.
|
|
85
|
+
- **retrieval** — query planning: intent detection, graph + semantic search, score fusion, normalization.
|
|
86
|
+
- **context** — agent-ready output: snippet selection under a character/token budget, reasons, scores, citations, and `missingEvidence`.
|
|
87
|
+
- **watch** — long-running watcher, durable event journal, dirty-file coalescing, and background batched re-index scheduling.
|
|
88
|
+
- **mcp** — thin protocol adaptation: tool names, input validation, handler dispatch. No search logic lives here.
|
|
89
|
+
|
|
90
|
+
The **context-pack contract** is the heart of the engine. `get_context` returns:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
brief → freshness → ownerChain → topology → evidence snippets → missingEvidence → nextQueries
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Snippets are *evidence*, not the primary organization. Large files default to a `skeleton` expansion level rather than full source, and every snippet reports how many lines were elided.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Getting Started
|
|
101
|
+
|
|
102
|
+
### Prerequisites
|
|
103
|
+
|
|
104
|
+
- **Node.js >= 24.0.0** (required — the SQLite graph store uses `node:sqlite`)
|
|
105
|
+
- Windows, macOS, or Linux
|
|
106
|
+
- ~100 MB disk for dependencies + index data
|
|
107
|
+
|
|
108
|
+
### Install and run (terminal-first, offline-first)
|
|
109
|
+
|
|
110
|
+
The first run needs no embedding API key, no account, and no hosted service.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Install globally
|
|
114
|
+
npm install -g ragcode-context-engine
|
|
115
|
+
|
|
116
|
+
cd my-project
|
|
117
|
+
ragcode init # offline-first config: sqlite + lancedb + deterministic embeddings
|
|
118
|
+
ragcode index . # build the structural + semantic index
|
|
119
|
+
ragcode setup-mcp # register the MCP server for your agent client
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Or try it without installing:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx ragcode-context-engine index .
|
|
126
|
+
npx ragcode-context-engine search . "query"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Working from source (no global install)? Run any command through the dev script — it executes the TypeScript entry directly via `tsx`:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run dev -- index .
|
|
133
|
+
npm run dev -- setup-mcp --client codex --print
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Upgrade semantic recall (optional, never a blocker)
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
ragcode configure # edit storage / provider / model / base URL / dimensions
|
|
140
|
+
ragcode configure --test # verify the provider (classified failures; secrets never printed)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
To use an OpenAI-compatible provider, set the embedding provider and key:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
export RAGCODE_EMBEDDING_PROVIDER=openai
|
|
147
|
+
export OPENAI_API_KEY=your-api-key
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`ragcode init` walks you through the full first-run flow; `ragcode <command> --help` documents each command's options.
|
|
151
|
+
|
|
152
|
+
### CLI commands
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
ragcode init [directory] # Initialize configuration (interactive wizard)
|
|
156
|
+
ragcode index <repoRoot> # Index a repository
|
|
157
|
+
ragcode search <repoRoot> <query> # Search code
|
|
158
|
+
ragcode status <repoRoot> # Check index status
|
|
159
|
+
ragcode context <repoRoot> <query> # Build a context pack
|
|
160
|
+
ragcode mcp # Start the MCP server (stdio)
|
|
161
|
+
ragcode setup-mcp # Register MCP for Claude Desktop
|
|
162
|
+
ragcode doctor [repoRoot] # Runtime diagnostics
|
|
163
|
+
ragcode watch <repoRoot> # File-watcher daemon
|
|
164
|
+
ragcode dashboard # Web observability backend (port 3000)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Run `ragcode --help` or `ragcode <command> --help` for details.
|
|
168
|
+
|
|
169
|
+
### MCP server integration
|
|
170
|
+
|
|
171
|
+
RagCode runs as an MCP server so agents like Claude can call its tools directly. Auto-register for your client:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
ragcode setup-mcp # Claude Desktop (~/.../claude_desktop_config.json)
|
|
175
|
+
ragcode setup-mcp --client claude-code # Claude Code (project ./.mcp.json)
|
|
176
|
+
ragcode setup-mcp --client codex # Codex CLI (~/.codex/config.toml)
|
|
177
|
+
ragcode setup-mcp --client codex --print # print config, write nothing
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Existing config is merged in place (other servers and unrelated keys are preserved, and the
|
|
181
|
+
previous file is backed up). Add `--force` to overwrite an existing `ragcode` entry without
|
|
182
|
+
prompting, and `--include-secrets` to embed the API key instead of redacting it.
|
|
183
|
+
|
|
184
|
+
Or add it manually to your MCP client config:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"mcpServers": {
|
|
189
|
+
"ragcode": {
|
|
190
|
+
"command": "ragcode",
|
|
191
|
+
"args": ["mcp"],
|
|
192
|
+
"env": {
|
|
193
|
+
"RAGCODE_GRAPH_STORE": "sqlite",
|
|
194
|
+
"RAGCODE_SQLITE_PATH": ".ragcode/graph.sqlite",
|
|
195
|
+
"RAGCODE_SEMANTIC_STORE": "lancedb",
|
|
196
|
+
"RAGCODE_LANCEDB_URI": ".ragcode/lancedb",
|
|
197
|
+
"RAGCODE_EMBEDDING_PROVIDER": "deterministic"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Available MCP tools (19):**
|
|
205
|
+
|
|
206
|
+
- *Index lifecycle* — `index_repo`, `refresh_index`, `index_status`, `record_file_events`, `watch_status`
|
|
207
|
+
- *Search & context* — `search_code`, `get_context`, `topology_map`, `expand_node`
|
|
208
|
+
- *Symbols & files* — `find_symbol`, `explain_file`, `find_owner`, `find_reuse_candidates`
|
|
209
|
+
- *Impact & flow* — `impact_analysis`, `explain_impact`, `related_tests`, `trace_flow`, `trace_request_flow`
|
|
210
|
+
- *Review* — `review_diff`
|
|
211
|
+
|
|
212
|
+
`watch_status` is read-only: it reports whether a live watcher is keeping the index fresh, but never starts one (that belongs to `ragcode watch` or the OS service).
|
|
213
|
+
|
|
214
|
+
### Web dashboard (observation and debugging)
|
|
215
|
+
|
|
216
|
+
The dashboard is RagCode's observability surface — graph visualization, search debugging, context-pack inspection, watcher monitoring, and a runtime-config view with per-field source labels and redacted secrets. Setup and configuration stay in the terminal.
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
ragcode dashboard # backend API (port 3000)
|
|
220
|
+
cd web && npm run dev # Vue frontend (port 5173, development)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
See [docs/DASHBOARD.md](docs/DASHBOARD.md) and [web/README.md](web/README.md).
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Project Structure
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
ragcode/
|
|
231
|
+
├── src/
|
|
232
|
+
│ ├── core/ # Canonical contracts and orchestration facade (stable boundary)
|
|
233
|
+
│ ├── indexing/ # Scan, ignore rules, hashing, chunking, analyzers, pipeline
|
|
234
|
+
│ ├── graph/ # Structural code graph: symbols, files, edges, lookup
|
|
235
|
+
│ ├── semantic/ # Embeddings + vector store (LanceDB / in-memory)
|
|
236
|
+
│ ├── retrieval/ # Query planning and hybrid (exact/graph/keyword/semantic) fusion
|
|
237
|
+
│ ├── context/ # Context-pack construction under token/char budgets
|
|
238
|
+
│ ├── subgraph/ # Verified code subgraph (impact / flow / review / debug)
|
|
239
|
+
│ ├── topology/ # Framework + dataflow topology edges
|
|
240
|
+
│ ├── reuse/ # Reuse / duplicate detection
|
|
241
|
+
│ ├── lsp/ # LSP-assisted symbol resolution
|
|
242
|
+
│ ├── watch/ # Watcher daemon, event journal, dirty coalescing, scheduler
|
|
243
|
+
│ ├── mcp/ # MCP tool definitions and handlers (thin adapter)
|
|
244
|
+
│ ├── cli/ # Command entrypoint (commander + ink wizards)
|
|
245
|
+
│ ├── web/ # Dashboard backend (express + ws)
|
|
246
|
+
│ ├── config/ # Runtime configuration resolution
|
|
247
|
+
│ ├── project/ # Project identity and workspace auto-scope
|
|
248
|
+
│ ├── diagnostics/ # Doctor / smoke checks
|
|
249
|
+
│ ├── types/ # Shared type declarations
|
|
250
|
+
│ └── utils/ # Small shared utilities (not domain owners)
|
|
251
|
+
├── tests/ # Vitest regression suites (foundation, graph, retrieval, watch, ...)
|
|
252
|
+
├── docs/ # Architecture notes, contracts, and decision records
|
|
253
|
+
├── integrations/ # Codex/OMX agent skill template (ragcode-context)
|
|
254
|
+
├── scripts/ # init-config, setup-mcp, benchmarks, eval, audit
|
|
255
|
+
├── web/ # Vue dashboard frontend
|
|
256
|
+
└── benchmarks/ # Benchmark fixtures and results
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Key Features
|
|
262
|
+
|
|
263
|
+
- **Hybrid retrieval** — fuses exact, graph, keyword, and semantic signals, then applies mode-specific boosts and graph-distance reranking. Candidates with non-positive final scores are filtered out.
|
|
264
|
+
- **Mode-aware context packing** — resolves a retrieval mode from the query: `debug`, `feature`, `refactor`, `review`, or `explain`, each prioritizing different evidence.
|
|
265
|
+
- **Context-pack contract** — `brief`, `freshness`, `ownerChain`, `topology`, evidence snippets, `missingEvidence`, and `nextQueries`, with citations and elision stats. Returning uncertainty beats overclaiming.
|
|
266
|
+
- **Structural code graph** — symbols, files, and `contains` / `imports` / `exports` / `calls` edges, backed by SQLite + FTS or an in-memory store.
|
|
267
|
+
- **Framework + dataflow topology** — bounded route/ORM evidence (Next.js, Express, Fastify, Prisma, Drizzle) emitted as `calls_api`, `routes_to`, `reads_from`, `writes_to`, and request-payload `orm_dataflow` edges.
|
|
268
|
+
- **Multi-language analysis** — full AST support for TypeScript/JavaScript via the TS Compiler API; tree-sitter–backed analysis for Python, Go, Rust, and Java, with fallback line chunking for other file types.
|
|
269
|
+
- **Incremental freshness** — chokidar OS watcher → durable event journal → dirty-file coalescing → background batched re-index. Restarts replay the journal so no dirty work is lost.
|
|
270
|
+
- **Offline-first** — deterministic embeddings require no API key; swap in an OpenAI-compatible provider whenever you want, without re-architecting.
|
|
271
|
+
- **MCP-native** — 19 agent tools over a thin stdio server (index lifecycle, search/context, impact/flow, review), plus a Codex/OMX skill template that routes agents to MCP first with CLI fallback.
|
|
272
|
+
- **Web observability** — graph visualization, search debugger, context-pack inspector, watcher monitor, and a redacted runtime-config view.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Development Workflow
|
|
277
|
+
|
|
278
|
+
Clone and set up:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
git clone https://github.com/MarshallEriksen-Neura/ragcode.git
|
|
282
|
+
cd ragcode
|
|
283
|
+
npm install
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Common tasks (npm is the canonical toolchain used by CI; `bun` also works locally):
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
npm run dev -- doctor # run the CLI from source via tsx
|
|
290
|
+
npm run check # TypeScript strict type check (no emit)
|
|
291
|
+
npm test # run the Vitest suite
|
|
292
|
+
npm run test:watcher # watcher-focused tests
|
|
293
|
+
npm run build # compile to dist/ via tsconfig.build.json
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Branching:** `main` is the protected default branch. Work on feature branches and open pull requests against `main` — never push directly to `main`.
|
|
297
|
+
|
|
298
|
+
**CI** ([.github/workflows/ci.yml](.github/workflows/ci.yml)) runs on every push and PR to `main` against Node 24 and enforces, in order: `npm ci` → `npm run check` → `npm run build` → `npm test` → `npm pack --dry-run`. All steps must pass before merge. Publishing is automated via [.github/workflows/publish.yml](.github/workflows/publish.yml).
|
|
299
|
+
|
|
300
|
+
Offline smoke run with deterministic embeddings:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
export RAGCODE_GRAPH_STORE=sqlite
|
|
304
|
+
export RAGCODE_SQLITE_PATH=.ragcode/graph.sqlite
|
|
305
|
+
export RAGCODE_SEMANTIC_STORE=lancedb
|
|
306
|
+
export RAGCODE_LANCEDB_URI=.ragcode/lancedb
|
|
307
|
+
export RAGCODE_EMBEDDING_PROVIDER=deterministic
|
|
308
|
+
|
|
309
|
+
npm run dev -- doctor . --query "context engine"
|
|
310
|
+
npm run dev -- index .
|
|
311
|
+
npm run dev -- search . "context engine"
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Coding Standards
|
|
317
|
+
|
|
318
|
+
- **TypeScript strict mode.** `npm run check` (`tsc --noEmit`) must pass with zero errors before any change is considered done.
|
|
319
|
+
- **ESM throughout.** The package is `"type": "module"`; use ES import/export and `node:`-prefixed builtins.
|
|
320
|
+
- **Respect layer boundaries.** Depend on the contracts in `src/core`, not concrete stores. `indexing` must not know about MCP; `mcp` must stay thin and contain no search logic; `watch` depends only on the `ContextEngine` contract.
|
|
321
|
+
- **Stores are replaceable.** Anything touching graph or semantic storage goes through the `GraphStore` / `SemanticStore` interfaces so tests and future backends can swap in.
|
|
322
|
+
- **Stable IDs and hashes.** Chunks have deterministic content hashes and stable IDs — preserve this when changing chunking or analyzers.
|
|
323
|
+
- **Validate inputs at the edges** with `zod`, especially MCP tool inputs.
|
|
324
|
+
- **Never print secrets.** Config views and provider tests redact API keys; sensitive files (`.env`, keys, credentials) are filtered from indexing.
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Testing
|
|
329
|
+
|
|
330
|
+
Tests use **Vitest** and live in [tests/](tests/) (38+ suites). They cover the full foundation: scanning and incremental indexing, SQLite and LanceDB stores, hybrid retrieval and graph reranking, context packing and skeletonization, topology resolution, the watcher daemon and journal replay, MCP server tools, and the onboarding/configure CLI wizards.
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
npm test # full suite
|
|
334
|
+
npm run test:watcher # watcher daemon + state tests only
|
|
335
|
+
npx vitest run tests/foundation.test.ts # a single suite
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The foundation is considered sound when a repo scans deterministically, chunks have stable IDs/hashes, graph and semantic stores are replaceable, CLI and MCP call the same engine, the strict type check passes, and scan/index/search/context-packing are all covered by tests. Add or update tests alongside any behavior change, and keep authoring and reviewing as separate passes.
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Contributing
|
|
343
|
+
|
|
344
|
+
1. Fork the repo and create a feature branch off `main`.
|
|
345
|
+
2. Make your change, keeping it within the relevant layer's boundary (see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)).
|
|
346
|
+
3. Add or update tests in [tests/](tests/) for any behavior change.
|
|
347
|
+
4. Run the full local gate before pushing:
|
|
348
|
+
```bash
|
|
349
|
+
npm run check && npm test && npm run build
|
|
350
|
+
```
|
|
351
|
+
5. Push your branch and open a pull request against `main` with a concise summary of what changed and what you tested.
|
|
352
|
+
|
|
353
|
+
For agent-assisted contribution, the Codex/OMX skill template in [integrations/codex/skills/ragcode-context/](integrations/codex/skills/ragcode-context/) routes agents to RagCode's MCP tools first, with CLI fallback and missing-index recovery — see [docs/CODEX_SKILL.md](docs/CODEX_SKILL.md).
|
|
354
|
+
|
|
355
|
+
### Further documentation
|
|
356
|
+
|
|
357
|
+
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — layers and ownership
|
|
358
|
+
- [docs/INDEX_SCHEMA.md](docs/INDEX_SCHEMA.md) — index schema
|
|
359
|
+
- [docs/DASHBOARD.md](docs/DASHBOARD.md) — web dashboard scope
|
|
360
|
+
- [docs/CODEX_SKILL.md](docs/CODEX_SKILL.md) — Codex/OMX agent skill template
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## License
|
|
365
|
+
|
|
366
|
+
Released under the [MIT License](./LICENSE). Copyright (c) 2026 RagCode Team.
|