remimem 0.0.0-stage → 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 +213 -2
- package/dist/chunker/index.js +129 -0
- package/dist/cli/commands.js +256 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/program.js +206 -0
- package/dist/config/index.js +108 -0
- package/dist/embedder/index.js +196 -0
- package/dist/errors.js +15 -0
- package/dist/graph/describe.js +90 -0
- package/dist/graph/index.js +224 -0
- package/dist/indexer/index.js +183 -0
- package/dist/indexer/overview.js +75 -0
- package/dist/indexer/watch.js +55 -0
- package/dist/log.js +16 -0
- package/dist/mcp/server.js +68 -0
- package/dist/mcp/tools.js +272 -0
- package/dist/memory/index.js +259 -0
- package/dist/packer/index.js +149 -0
- package/dist/parser/index.js +294 -0
- package/dist/retriever/index.js +186 -0
- package/dist/scanner/index.js +129 -0
- package/dist/stats/index.js +32 -0
- package/dist/store/fts.js +26 -0
- package/dist/store/index.js +633 -0
- package/dist/tokens.js +8 -0
- package/grammars/README.md +15 -0
- package/grammars/ecma.scm +42 -0
- package/grammars/go.scm +37 -0
- package/grammars/go.wasm +0 -0
- package/grammars/javascript.scm +6 -0
- package/grammars/javascript.wasm +0 -0
- package/grammars/python.scm +21 -0
- package/grammars/python.wasm +0 -0
- package/grammars/tsx.wasm +0 -0
- package/grammars/typescript.scm +20 -0
- package/grammars/typescript.wasm +0 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jaswanth Remiel AG
|
|
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
CHANGED
|
@@ -1,3 +1,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# remimem
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
remimem: codebase memory for coding agents.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
It is a local-first MCP server and CLI that indexes a codebase and gives coding agents (Claude Code, Cursor, VS Code Copilot, any MCP client) the smallest set of code that answers their question, within a token budget. It also keeps project memory, decisions and conventions that persist across sessions, and ships the benchmark below so the savings can be checked.
|
|
8
|
+
|
|
9
|
+
## Benchmark
|
|
10
|
+
|
|
11
|
+
How much context does remimem save, and does it find the right code? Each task is a real commit from an open-source repository, described by its commit message. The code is indexed as it was just before that commit, and a strategy is scored on whether it returns the files and symbols the commit went on to change. The baseline imitates an agent that greps for keywords and reads whole files.
|
|
12
|
+
|
|
13
|
+
<!-- prettier-ignore-start -->
|
|
14
|
+
<!-- bench:start -->
|
|
15
|
+
|
|
16
|
+
Measured on 2026-11-15 with remimem `9e63d69` on Apple M5 (10 cores, 16 GB, darwin 27.2.0, Node.js v24.20.0), embedding model `local:Xenova/all-MiniLM-L6-v2`. Test split: 36 of 108 tasks, held out from tuning. Ground-truth files are the non-test source files a task's commit changed. Token counts are approximate.
|
|
17
|
+
|
|
18
|
+
**Headline (test split, 36 tasks, `get_context@4000` against the grep baseline).** Tokens: remimem serves 3,827 per call on average; the baseline reads 27,529 per task on average, with each task where it did not read every ground-truth file counted at its 40,000-token cap. That is 86% fewer (target: at least 40% fewer). Charging remimem the same cap for each task where its answer lacks a ground-truth file gives 6,854, 75% fewer. Recall@10: on average 0.93 of a task's ground-truth files are among the ten best-ranked files (baseline 0.79; target 0.80). File recall in the answer: 93% (baseline 60%); counting a file only when a full body from it is shown, not a signature-only block: 92%.
|
|
19
|
+
|
|
20
|
+
**The same without httpx `cabd1c095e`** (35 tasks), a test task that was inspected while the harness was being debugged, before tuning: Tokens: remimem serves 3,823 per call on average; the baseline reads 27,535 per task on average, with each task where it did not read every ground-truth file counted at its 40,000-token cap. That is 86% fewer (target: at least 40% fewer). Charging remimem the same cap for each task where its answer lacks a ground-truth file gives 6,937, 75% fewer. Recall@10: on average 0.93 of a task's ground-truth files are among the ten best-ranked files (baseline 0.79; target 0.80). File recall in the answer: 93% (baseline 59%); counting a file only when a full body from it is shown, not a signature-only block: 92%.
|
|
21
|
+
|
|
22
|
+
| Strategy | Tokens per task | File recall | File recall, full body only | Symbol recall | Recall@10 | MRR | Reached | Tokens to first hit | Latency p50 / p95 |
|
|
23
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
24
|
+
| baseline: grep and read whole files, 40,000-token cap | 27,529 | 60% | 60% | 57% | 0.79 | 0.40 | 61% | 16,374 | 5 / 9 ms |
|
|
25
|
+
| `search_code` at 2,000 tokens | 1,895 | 83% | 80% | 73% | 0.85 | 0.60 | 86% | 534 | 14 / 28 ms |
|
|
26
|
+
| `search_code` at 4,000 tokens | 3,353 | 85% | 85% | 74% | 0.85 | 0.60 | 89% | 1,126 | 18 / 30 ms |
|
|
27
|
+
| `search_code` at 8,000 tokens | 3,913 | 85% | 85% | 77% | 0.85 | 0.60 | 89% | 953 | 20 / 30 ms |
|
|
28
|
+
| `get_context` at 2,000 tokens | 1,943 | 87% | 81% | 67% | 0.93 | 0.61 | 89% | 630 | 15 / 28 ms |
|
|
29
|
+
| `get_context` at 4,000 tokens | 3,827 | 93% | 92% | 74% | 0.93 | 0.61 | 94% | 1,228 | 20 / 30 ms |
|
|
30
|
+
| `get_context` at 8,000 tokens | 6,218 | 93% | 93% | 78% | 0.93 | 0.61 | 94% | 1,232 | 27 / 43 ms |
|
|
31
|
+
|
|
32
|
+
Columns: *tokens per task* is the mean size of the answer; for the baseline it is what it read, with a task counted at the 40,000-token cap when it did not read every ground-truth file. *File recall* and *symbol recall* are the share of ground-truth files and symbols present in what was returned (for the baseline, in the files it read); *full body only* does not count a file that appears only as a signature. *Recall@10* is the share of a task's ground-truth files among the ten best-ranked files, averaged over tasks, and *MRR* the mean reciprocal rank of the first one. *Reached* is the share of tasks in which any ground-truth file was returned, and *tokens to first hit* the median over those tasks.
|
|
33
|
+
|
|
34
|
+
Ablations of `get_context` at 4,000 tokens (test split):
|
|
35
|
+
|
|
36
|
+
| Strategy | Tokens per task | File recall | File recall, full body only | Symbol recall | Recall@10 | MRR | Reached | Tokens to first hit | Latency p50 / p95 |
|
|
37
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
38
|
+
| full | 3,827 | 93% | 92% | 74% | 0.93 | 0.61 | 94% | 1,228 | 20 / 30 ms |
|
|
39
|
+
| keyword only | 3,824 | 80% | 77% | 68% | 0.88 | 0.54 | 81% | 1,022 | 16 / 23 ms |
|
|
40
|
+
| vector only | 3,690 | 79% | 76% | 50% | 0.85 | 0.53 | 83% | 800 | 18 / 29 ms |
|
|
41
|
+
| no graph expansion | 3,594 | 92% | 92% | 67% | 0.93 | 0.62 | 94% | 1,212 | 18 / 30 ms |
|
|
42
|
+
| no signature compression | 3,896 | 90% | 90% | 67% | 0.93 | 0.61 | 92% | 1,228 | 22 / 32 ms |
|
|
43
|
+
| no name-match edges | 3,794 | 93% | 92% | 71% | 0.93 | 0.61 | 94% | 1,228 | 19 / 30 ms |
|
|
44
|
+
| with memories | 3,829 | 93% | 90% | 74% | 0.93 | 0.61 | 94% | 1,272 | 26 / 42 ms |
|
|
45
|
+
|
|
46
|
+
Memory ablation: each repo gets 60 memories made from older commit subjects, unlinked, so they have to match the task text. With memories on, 2.4 are attached per task; 25% of attached memories come from a commit that touched a ground-truth file, and 54% of the tasks that have such a memory get at least one.
|
|
47
|
+
|
|
48
|
+
Per repository (test split):
|
|
49
|
+
|
|
50
|
+
| Repository | Language | Lines | Tasks | Baseline tokens per task | `get_context` tokens per task | Baseline recall@10 | `get_context` recall@10 | Baseline file recall | `get_context` file recall |
|
|
51
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
52
|
+
| [hono](https://github.com/honojs/hono) at `f6fbaf0299` (MIT) | typescript | 99,158 | 12 | 27,622 | 3,866 | 0.67 | 1.00 | 58% | 100% |
|
|
53
|
+
| [httpx](https://github.com/encode/httpx) at `b5addb64f0` (BSD-3-Clause) | python | 33,460 | 12 | 28,072 | 3,773 | 0.71 | 0.83 | 71% | 83% |
|
|
54
|
+
| [echo](https://github.com/labstack/echo) at `f275a6b110` (MIT) | go | 49,731 | 12 | 26,892 | 3,842 | 1.00 | 0.96 | 50% | 96% |
|
|
55
|
+
|
|
56
|
+
Worst misses of `get_context@4000` on the test split (3 shown):
|
|
57
|
+
|
|
58
|
+
- httpx `609df7ecc0`: "Reintroduce `URLTypes`. (#3288)" wanted `httpx/__version__.py`, `httpx/_types.py`; file recall 0%, first ground-truth file ranked nowhere.
|
|
59
|
+
- httpx `9fd6f0ca66`: "Ensure JSON representation is compact. #3363 (#3367)" wanted `httpx/_content.py`; file recall 0%, first ground-truth file ranked nowhere.
|
|
60
|
+
- echo `8d1ae9d336`: "fix(static): reject encoded path separators that bypass route-level middleware (#3009)" wanted `echo.go`, `middleware/static.go`; file recall 50%, first ground-truth file ranked 1.
|
|
61
|
+
|
|
62
|
+
Embedding models compared (`get_context@4000`, test split):
|
|
63
|
+
|
|
64
|
+
| Model | Tokens per task | File recall | File recall, full body only | Symbol recall | Recall@10 | MRR | Latency p50 / p95 | First full index of all repos |
|
|
65
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
66
|
+
| `local:Xenova/all-MiniLM-L6-v2` | 3,827 | 93% | 92% | 74% | 0.93 | 0.61 | 20 / 30 ms | 62s |
|
|
67
|
+
| `local:jinaai/jina-embeddings-v2-base-code` | 3,769 | 92% | 92% | 74% | 0.93 | 0.65 | 35 / 83 ms | 324s |
|
|
68
|
+
|
|
69
|
+
Re-indexing after a 20-file change on hono: 0.57s.
|
|
70
|
+
|
|
71
|
+
Reproduce with `npm install && npx . bench` from a clone. Results vary slightly between CPU types, because the quantized embedding model rounds differently; `npx . bench --compare <results file>` reruns and checks each headline figure against a tolerance.
|
|
72
|
+
|
|
73
|
+
<!-- bench:end -->
|
|
74
|
+
<!-- prettier-ignore-end -->
|
|
75
|
+
|
|
76
|
+
What these numbers do not show: the tasks are commit messages, which are written after the change and can name the place that was changed, so they are easier than a bug report written beforehand. The test split is 36 tasks, so one task moves a percentage by about three points. The baseline is a simulation, not a real agent. One test-split task was looked at while the harness was being debugged, before any tuning; the settings it prompted were then chosen on the training split alone, and the headline is given with and without it. The method is described in [SETUP.md](SETUP.md#run-the-benchmark).
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
In the project you want to index (Node.js 22.13 or newer):
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npx -y remimem init
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This creates `.remimem/`, builds the index, and prints the client configuration below. The first run downloads a 23 MB embedding model; after that nothing needs the network. To build from source instead, see [SETUP.md](SETUP.md).
|
|
87
|
+
|
|
88
|
+
## Connect your agent
|
|
89
|
+
|
|
90
|
+
**Claude Code.** Run this in the project:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
claude mcp add remimem -- npx -y remimem serve
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
or create `.mcp.json` in the project root:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"mcpServers": {
|
|
101
|
+
"remimem": { "command": "npx", "args": ["-y", "remimem", "serve"] }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Cursor.** Create `.cursor/mcp.json` in the project root with the same content.
|
|
107
|
+
|
|
108
|
+
**VS Code (Copilot).** Create `.mcp.json` in the workspace root:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"mcpServers": {
|
|
113
|
+
"remimem": { "type": "stdio", "command": "npx", "args": ["-y", "remimem", "serve"] }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Older VS Code versions read `.vscode/mcp.json` instead, which uses a `servers` key:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"servers": {
|
|
123
|
+
"remimem": { "type": "stdio", "command": "npx", "args": ["-y", "remimem", "serve"] }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The server works on the directory it is started in; add `"--root", "<path>"` to the args to point it elsewhere.
|
|
129
|
+
|
|
130
|
+
## How it works
|
|
131
|
+
|
|
132
|
+
- **Index by structure.** Files are parsed with tree-sitter (TypeScript, JavaScript, Python, Go) into functions, methods, classes, and types; every other text file is indexed in line windows.
|
|
133
|
+
- **Search three ways.** A query runs against a keyword index that understands identifiers, a vector index built by a local embedding model, and an exact lookup of symbol names. The rankings are fused.
|
|
134
|
+
- **Follow the call graph.** Callers, callees, base classes, and referenced types of the top results are added as signatures, each with the reason it is there.
|
|
135
|
+
- **Pack to a budget.** Results are fitted into the token budget you give, grouped by file in line order with `path:start-end` headers. The answer never exceeds the budget and says what was dropped.
|
|
136
|
+
- **Remember.** Decisions, conventions, and gotchas are stored with links to code, shown at the top of later answers, and flagged when the code they are about changes.
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
files -> scanner -> parser -> chunker -> SQLite (keyword index, vectors, call graph, memory)
|
|
140
|
+
|
|
|
141
|
+
agent -> MCP tool -> retriever (keyword + vector + graph) -> packer -> text within the budget
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Changed files are re-indexed before each tool call, so answers follow your edits.
|
|
145
|
+
|
|
146
|
+
## Tools
|
|
147
|
+
|
|
148
|
+
| Tool | What it returns |
|
|
149
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
150
|
+
| `get_context` | The best starting context for a task: project memory, the top code in full, and neighbor signatures. Inputs: `task`, `budget_tokens` (default 4,000), `paths`. |
|
|
151
|
+
| `search_code` | Ranked code for a query, with the reason each result matched. Inputs: `query`, `k` (default 10), `budget_tokens`, `language`, `paths`. |
|
|
152
|
+
| `get_symbol` | One function, class, or type with its callers and callees. Inputs: `name`, `include` (`body` or `signature`), `depth` (0 to 2). |
|
|
153
|
+
| `get_file_outline` | The symbols of a file with signatures and line numbers, no bodies. Input: `path`. |
|
|
154
|
+
| `find_references` | Where a symbol is called, extended, used as a type, or imported, as `path:line` grouped by file. Input: `name`. |
|
|
155
|
+
| `remember` | Saves a decision, convention, gotcha, or todo, optionally linked to files and symbols. Inputs: `text`, `kind`, `paths`, `symbols`, `tags`. |
|
|
156
|
+
| `recall` | Matching memories, stale ones marked. Inputs: `query`, `kind`. |
|
|
157
|
+
| `forget` | Deletes a memory. Input: `id`. |
|
|
158
|
+
| `index_status` | Files, chunks, last indexed commit, pending changes, embedding model. |
|
|
159
|
+
|
|
160
|
+
There is also one resource, `remimem://overview`: a directory map with the most-referenced symbols per directory.
|
|
161
|
+
|
|
162
|
+
The same functions are available from the command line: `remimem init`, `index [--full]`, `watch`, `serve`, `search "<query>"`, `context "<task>"`, `memory list|add|rm`, `stats`, `doctor`, and `bench` (from a source checkout).
|
|
163
|
+
|
|
164
|
+
## Configuration
|
|
165
|
+
|
|
166
|
+
Optional, in `.remimem/config.json`. Every setting has a default; unknown keys are rejected.
|
|
167
|
+
|
|
168
|
+
| Setting | Default | Meaning |
|
|
169
|
+
| ----------------------------------------------------------------------- | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| `include`, `exclude` | none | Globs that limit which files are indexed. Vendored, generated, binary, oversized, and secret-looking files are always skipped. |
|
|
171
|
+
| `maxFileSizeKb` | 512 | Larger files are skipped. |
|
|
172
|
+
| `embedding.provider` | `local` | `local`, `none` (keyword search only), or `openai` and `voyage`, which send code to that service. Keys come from `OPENAI_API_KEY` or `VOYAGE_API_KEY`, never from this file. |
|
|
173
|
+
| `embedding.model` | `Xenova/all-MiniLM-L6-v2` | Changing it needs `remimem index --full`. |
|
|
174
|
+
| `retrieval.defaultBudgetTokens` | 4000 | Budget when a call does not give one. |
|
|
175
|
+
| `retrieval.rrfK`, `keywordLimit`, `vectorLimit`, `keywordWeights` | 60, 50, 50, content 1 / symbol 5 / path 2 | Ranking fusion. |
|
|
176
|
+
| `retrieval.textFileWeight` | 0.25 | How much a result from a file that is not parsed as code counts against one from code. |
|
|
177
|
+
| `retrieval.graphTopN`, `graphMaxNeighbors`, `edgeWeights` | 10, 20, exact 0.5 / import 0.4 / name-match 0.2 | Call graph expansion. |
|
|
178
|
+
| `retrieval.memoryLimit`, `memoryMinKeywordMatch`, `memoryMinSimilarity` | 5, 0.5, 0.4 | Which memories `get_context` attaches. |
|
|
179
|
+
| `watch.debounceMs` | 500 | How long `remimem watch` waits after the last change. |
|
|
180
|
+
|
|
181
|
+
Memories are mirrored to `.remimem/memory.json`, which is meant to be committed so a team shares them. The index, `.remimem/index.db`, is local and is added to `.gitignore` by `init`.
|
|
182
|
+
|
|
183
|
+
## Privacy
|
|
184
|
+
|
|
185
|
+
Everything runs on your machine. Code is parsed, embedded, and stored locally, in one SQLite file inside the project. Nothing is sent anywhere unless you set `embedding.provider` to `openai` or `voyage`, in which case the text of indexed code goes to that service to be embedded. There is no telemetry. The query log behind `remimem stats` stays in the local index. The one network request in the default setup is the first download of the embedding model from huggingface.co.
|
|
186
|
+
|
|
187
|
+
## Limitations
|
|
188
|
+
|
|
189
|
+
- **The benchmark tasks are commit messages.** They are written after the change and often name what changed, so they are easier than bug reports. The test split is 36 tasks from three repositories, and the baseline is a simulation of a grep-driven agent, not a real one.
|
|
190
|
+
- **Documentation is down-weighted.** Results from files that are not parsed as code (Markdown, JSON, SQL) count a quarter by default, because changelogs were crowding out code. If you search mostly for prose, raise `retrieval.textFileWeight`.
|
|
191
|
+
- **No type inference.** The call graph resolves names, not types: `user.save()` is linked only when one symbol in the repo is named `save`. In a hand-check on a large TypeScript repo about one in four of these name-match links was wrong. Calls into libraries have no links at all.
|
|
192
|
+
- **Structural parsing covers four languages.** TypeScript, JavaScript, Python, and Go. Everything else is searchable as text in line windows, without symbols or a call graph.
|
|
193
|
+
- **The OpenAI and Voyage embedding providers are tested only against stubs.** They have never been run against the live services.
|
|
194
|
+
- **Install size.** The local embedding runtime brings about 430 MB into `node_modules`, and a first `npx` run downloads and unpacks about 750 MB.
|
|
195
|
+
- **The end-to-end benchmark hook has never been run.** `remimem bench --e2e` prints a cost estimate and does nothing more without `--yes`; the agent flags it would use are unverified.
|
|
196
|
+
- **Memories cost a little code.** With project memory attached, the share of right files shown with a full body dropped by about 2 points in the benchmark (90% against 92%), because memory takes up to a quarter of the budget. Only a quarter of the memories attached there were relevant.
|
|
197
|
+
- **The default embedding model is not trained on code.** A code-trained alternative found no more of the right files in the benchmark and indexed five times slower, so it is an option, not the default.
|
|
198
|
+
- **Change detection trusts size and modification time.** A change that keeps both is missed until `remimem index` runs, which hashes every file.
|
|
199
|
+
- **Platform gaps.** Vector search has no prebuilt extension for Windows on ARM. TypeScript path aliases from `tsconfig.json` are not read. Go struct embedding and implicit interface satisfaction produce no graph links.
|
|
200
|
+
|
|
201
|
+
## Roadmap
|
|
202
|
+
|
|
203
|
+
- More languages at structural depth: Java, Rust, C#.
|
|
204
|
+
- Team mode: a shared index and memory with access control.
|
|
205
|
+
- A pull request reviewer that uses project memory and conventions to flag violations.
|
|
206
|
+
- Smarter context: reranking with a small cross-encoder, and learning from which results agents open.
|
|
207
|
+
|
|
208
|
+
## Contributing
|
|
209
|
+
|
|
210
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), which includes how to add a language. [SETUP.md](SETUP.md) covers building, testing, and verifying each part, [DECISIONS.md](DECISIONS.md) records why things are the way they are, and [CHANGELOG.md](CHANGELOG.md) lists what changed.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
export const DEFAULT_CHUNK_OPTIONS = {
|
|
3
|
+
maxChunkLines: 80,
|
|
4
|
+
windowLines: 60,
|
|
5
|
+
windowOverlap: 10,
|
|
6
|
+
};
|
|
7
|
+
// shortcut: class header chunks are never split, even for a class with hundreds of fields.
|
|
8
|
+
// Split them if such headers start crowding out other results.
|
|
9
|
+
/** Kinds that get their own chunk. Constants stay in the line windows around them. */
|
|
10
|
+
const CHUNKED = new Set(['function', 'method', 'class', 'interface', 'type', 'enum']);
|
|
11
|
+
const hash = (text) => createHash('sha256').update(text).digest('hex');
|
|
12
|
+
/** Line ranges of `windowLines` with `windowOverlap` shared lines, covering `from` to `to`. */
|
|
13
|
+
export function windows(from, to, opts) {
|
|
14
|
+
const out = [];
|
|
15
|
+
const step = Math.max(1, opts.windowLines - opts.windowOverlap);
|
|
16
|
+
for (let start = from; start <= to; start += step) {
|
|
17
|
+
const end = Math.min(start + opts.windowLines - 1, to);
|
|
18
|
+
out.push([start, end]);
|
|
19
|
+
if (end === to)
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Splits `from..to` before statements so each part stays within `max` lines where possible.
|
|
26
|
+
* A single statement longer than `max` stays whole here; `chunkFile` cuts it by line count.
|
|
27
|
+
*/
|
|
28
|
+
export function splitAtStatements(from, to, stmtLines, max) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
let partStart = from;
|
|
31
|
+
for (let i = 1; i < stmtLines.length; i++) {
|
|
32
|
+
const next = stmtLines[i];
|
|
33
|
+
const afterNext = stmtLines[i + 1] ?? to + 1;
|
|
34
|
+
if (afterNext - partStart > max && next > partStart) {
|
|
35
|
+
parts.push([partStart, next - 1]);
|
|
36
|
+
partStart = next;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
parts.push([partStart, to]);
|
|
40
|
+
return parts;
|
|
41
|
+
}
|
|
42
|
+
/** Turns one file into chunks. `source` must use LF line endings. */
|
|
43
|
+
export function chunkFile(path, language, source, parsed, opts = DEFAULT_CHUNK_OPTIONS) {
|
|
44
|
+
const lines = source.split('\n');
|
|
45
|
+
if (lines.at(-1) === '')
|
|
46
|
+
lines.pop(); // trailing newline
|
|
47
|
+
const text = (from, to) => lines.slice(from - 1, to).join('\n');
|
|
48
|
+
const chunks = [];
|
|
49
|
+
const add = (range, content, sym, parent, symbolIndex = null) => {
|
|
50
|
+
chunks.push({
|
|
51
|
+
path,
|
|
52
|
+
language,
|
|
53
|
+
symbol: sym?.qualifiedName ?? null,
|
|
54
|
+
symbolIndex,
|
|
55
|
+
kind: sym?.kind ?? 'window',
|
|
56
|
+
signature: sym?.signature ?? '',
|
|
57
|
+
docstring: sym?.docstring ?? '',
|
|
58
|
+
startLine: range[0],
|
|
59
|
+
endLine: range[1],
|
|
60
|
+
parent,
|
|
61
|
+
content,
|
|
62
|
+
contentHash: hash(content),
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const covered = new Array(lines.length + 2).fill(false);
|
|
66
|
+
const symbols = parsed?.symbols ?? [];
|
|
67
|
+
for (const [index, sym] of symbols.entries()) {
|
|
68
|
+
const parent = sym.parent === null ? null : symbols[sym.parent];
|
|
69
|
+
// Symbols nested in a function stay inside that function's chunk.
|
|
70
|
+
if (!CHUNKED.has(sym.kind) || (parent && parent.kind !== 'class'))
|
|
71
|
+
continue;
|
|
72
|
+
const from = sym.docStartLine;
|
|
73
|
+
const to = Math.min(sym.endLine, lines.length);
|
|
74
|
+
const parentName = parent?.qualifiedName ?? null;
|
|
75
|
+
for (let line = from; line <= to; line++)
|
|
76
|
+
covered[line] = true;
|
|
77
|
+
if (sym.kind === 'class') {
|
|
78
|
+
add([from, to], classHeader(lines, language, from, to, symbols, index), sym, parentName, index);
|
|
79
|
+
}
|
|
80
|
+
else if (to - from + 1 > opts.maxChunkLines) {
|
|
81
|
+
const parts = splitAtStatements(from, to, sym.stmtLines, opts.maxChunkLines).flatMap(
|
|
82
|
+
// A single statement can still be too long: cut it into plain line blocks.
|
|
83
|
+
([a, b]) => windows(a, b, { ...opts, windowLines: opts.maxChunkLines, windowOverlap: 0 }));
|
|
84
|
+
for (const [i, part] of parts.entries()) {
|
|
85
|
+
const body = text(part[0], part[1]);
|
|
86
|
+
add(part, i === 0 ? body : `${sym.signature}\n${body}`, sym, parentName, index);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
add([from, to], text(from, to), sym, parentName, index);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Everything no symbol chunk covers (imports, constants, top-level code, or the whole
|
|
94
|
+
// file for unsupported languages) becomes line windows.
|
|
95
|
+
for (let line = 1; line <= lines.length; line++) {
|
|
96
|
+
if (covered[line] || lines[line - 1].trim() === '')
|
|
97
|
+
continue;
|
|
98
|
+
let end = line;
|
|
99
|
+
for (let next = line + 1; next <= lines.length && !covered[next]; next++) {
|
|
100
|
+
if (lines[next - 1].trim() !== '')
|
|
101
|
+
end = next;
|
|
102
|
+
}
|
|
103
|
+
// A run with no word characters is leftover punctuation, such as a closing bracket.
|
|
104
|
+
if (/\w/.test(text(line, end))) {
|
|
105
|
+
for (const range of windows(line, end, opts))
|
|
106
|
+
add(range, text(range[0], range[1]), null, null);
|
|
107
|
+
}
|
|
108
|
+
line = end;
|
|
109
|
+
}
|
|
110
|
+
return chunks.sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine);
|
|
111
|
+
}
|
|
112
|
+
/** The class text with the bodies of its own methods replaced by a placeholder. */
|
|
113
|
+
function classHeader(lines, language, from, to, symbols, classIndex) {
|
|
114
|
+
let offset = 0;
|
|
115
|
+
for (let i = 0; i < from - 1; i++)
|
|
116
|
+
offset += lines[i].length + 1;
|
|
117
|
+
let header = lines.slice(from - 1, to).join('\n');
|
|
118
|
+
const placeholder = language === 'python' ? '...' : '{ ... }';
|
|
119
|
+
const bodies = symbols
|
|
120
|
+
.filter((s) => s.parent === classIndex && s.kind === 'method' && s.body)
|
|
121
|
+
.map((s) => s.body)
|
|
122
|
+
// Go methods are declared outside the type, so their bodies are not in this text.
|
|
123
|
+
.filter(([start, end]) => start >= offset && end <= offset + header.length)
|
|
124
|
+
.sort((a, b) => b[0] - a[0]);
|
|
125
|
+
for (const [start, end] of bodies) {
|
|
126
|
+
header = header.slice(0, start - offset) + placeholder + header.slice(end - offset);
|
|
127
|
+
}
|
|
128
|
+
return header;
|
|
129
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { CONFIG_DIR, loadConfig } from '../config/index.js';
|
|
5
|
+
import { StoreError } from '../errors.js';
|
|
6
|
+
import { describeSymbol, findReferences } from '../graph/describe.js';
|
|
7
|
+
import { indexRepo, pendingChanges } from '../indexer/index.js';
|
|
8
|
+
import { startWatch } from '../indexer/watch.js';
|
|
9
|
+
import { LANGS, parseSource } from '../parser/index.js';
|
|
10
|
+
import { createProvider } from '../embedder/index.js';
|
|
11
|
+
import { pack } from '../packer/index.js';
|
|
12
|
+
import { search } from '../retriever/index.js';
|
|
13
|
+
import { Store } from '../store/index.js';
|
|
14
|
+
import { runTool, TOOLS } from '../mcp/tools.js';
|
|
15
|
+
import { formatStats } from '../stats/index.js';
|
|
16
|
+
const dbPath = (root) => join(root, CONFIG_DIR, 'index.db');
|
|
17
|
+
/** `remimem index`: returns the summary line. */
|
|
18
|
+
export async function runIndex(root, options) {
|
|
19
|
+
const config = loadConfig(root);
|
|
20
|
+
mkdirSync(join(root, CONFIG_DIR), { recursive: true });
|
|
21
|
+
const store = new Store(dbPath(root));
|
|
22
|
+
try {
|
|
23
|
+
const provider = createProvider(config.embedding);
|
|
24
|
+
const stats = await indexRepo(root, store, config, { ...options, provider });
|
|
25
|
+
const total = store.counts();
|
|
26
|
+
const vectors = provider
|
|
27
|
+
? ` Embedded ${stats.embedded} chunks (${stats.embeddingsCached} from cache) with ${provider.id}.`
|
|
28
|
+
: ' Embeddings are off.';
|
|
29
|
+
return `${describeRun(stats)}${vectors} Index: ${total.files} files, ${total.symbols} symbols, ${total.chunks} chunks.`;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
store.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** `remimem search`: returns the packed results as text. */
|
|
36
|
+
export async function runSearch(root, query, options) {
|
|
37
|
+
if (!existsSync(dbPath(root))) {
|
|
38
|
+
throw new StoreError('No index found in this directory; run `remimem index` first');
|
|
39
|
+
}
|
|
40
|
+
const config = loadConfig(root);
|
|
41
|
+
const store = new Store(dbPath(root));
|
|
42
|
+
try {
|
|
43
|
+
const provider = createProvider(config.embedding);
|
|
44
|
+
// The same quick check the MCP server runs before a tool call: pick up changed files.
|
|
45
|
+
await indexRepo(root, store, config, { quick: true, provider });
|
|
46
|
+
const results = await search(store, query, config.retrieval, provider, options.k);
|
|
47
|
+
const packed = pack(results, options.budget ?? config.retrieval.defaultBudgetTokens, '', config.retrieval.neighborBudgetShare);
|
|
48
|
+
if (!options.debug)
|
|
49
|
+
return packed.text;
|
|
50
|
+
const scores = results.map(({ chunk, score, ranks }, i) => {
|
|
51
|
+
const fit = packed.included.some((item) => item.chunk.id === chunk.id) ? '' : ' (dropped)';
|
|
52
|
+
const ranksText = `keyword=${ranks.keyword ?? '-'} vector=${ranks.vector ?? '-'}`;
|
|
53
|
+
return `${i + 1}. score=${score.toFixed(4)} ${ranksText} ${chunk.path}:${chunk.startLine}-${chunk.endLine} ${chunk.symbol ?? 'lines'}${fit}`;
|
|
54
|
+
});
|
|
55
|
+
return `${scores.join('\n')}\n\n${packed.text}`;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
store.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** `remimem context`: what the `get_context` tool returns, for pasting into any chat. */
|
|
62
|
+
export async function runContext(root, task, options) {
|
|
63
|
+
const config = loadConfig(root);
|
|
64
|
+
const getContext = TOOLS.find((tool) => tool.name === 'get_context');
|
|
65
|
+
return withStore(root, async (store) => {
|
|
66
|
+
const ctx = { root, config, store, provider: createProvider(config.embedding) };
|
|
67
|
+
if (!getContext)
|
|
68
|
+
return '';
|
|
69
|
+
// Unlike the server, a command cannot finish a refresh in the background: wait for it.
|
|
70
|
+
await indexRepo(root, store, config, { quick: true, provider: ctx.provider });
|
|
71
|
+
return runTool(ctx, getContext, { task, budget_tokens: options.budget }, { refresh: false });
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** `remimem memory list`, `add`, and `rm`: the memory tools from the command line. */
|
|
75
|
+
export async function runMemory(root, action, args) {
|
|
76
|
+
const config = loadConfig(root);
|
|
77
|
+
const name = { list: 'recall', add: 'remember', rm: 'forget' }[action];
|
|
78
|
+
const memoryTool = TOOLS.find((tool) => tool.name === name);
|
|
79
|
+
mkdirSync(join(root, CONFIG_DIR), { recursive: true });
|
|
80
|
+
const store = new Store(dbPath(root));
|
|
81
|
+
try {
|
|
82
|
+
const ctx = { root, config, store, provider: createProvider(config.embedding) };
|
|
83
|
+
return memoryTool ? await runTool(ctx, memoryTool, args, { refresh: false }) : '';
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
store.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** How an MCP client should start this copy of remimem. */
|
|
90
|
+
function serverCommand() {
|
|
91
|
+
const cli = fileURLToPath(new URL('./index.js', import.meta.url));
|
|
92
|
+
// An installed package is started through npx; a source checkout by its path.
|
|
93
|
+
return cli.includes('node_modules')
|
|
94
|
+
? { command: 'npx', args: ['-y', 'remimem', 'serve'] }
|
|
95
|
+
: { command: 'node', args: [cli, 'serve'] };
|
|
96
|
+
}
|
|
97
|
+
/** Copy-paste MCP configuration for the supported clients. */
|
|
98
|
+
export function clientConfigs() {
|
|
99
|
+
const { command, args } = serverCommand();
|
|
100
|
+
const json = (server) => JSON.stringify({ mcpServers: { remimem: server } }, null, 2);
|
|
101
|
+
const shell = [command, ...args].map((part) => (/\s/.test(part) ? `"${part}"` : part)).join(' ');
|
|
102
|
+
return [
|
|
103
|
+
'Connect an MCP client (run it from this directory, or add "--root", "<path>" to the args):',
|
|
104
|
+
'',
|
|
105
|
+
'Claude Code, either run:',
|
|
106
|
+
` claude mcp add remimem -- ${shell}`,
|
|
107
|
+
'or create .mcp.json in the project root:',
|
|
108
|
+
json({ command, args }),
|
|
109
|
+
'',
|
|
110
|
+
'Cursor: create .cursor/mcp.json in the project root:',
|
|
111
|
+
json({ command, args }),
|
|
112
|
+
'',
|
|
113
|
+
'VS Code (Copilot): create .mcp.json in the workspace root:',
|
|
114
|
+
json({ type: 'stdio', command, args }),
|
|
115
|
+
'Older VS Code versions read .vscode/mcp.json instead:',
|
|
116
|
+
JSON.stringify({ servers: { remimem: { type: 'stdio', command, args } } }, null, 2),
|
|
117
|
+
].join('\n');
|
|
118
|
+
}
|
|
119
|
+
/** `remimem init`: config, .gitignore entry, first index, and client setup instructions. */
|
|
120
|
+
export async function runInit(root, options) {
|
|
121
|
+
const dir = join(root, CONFIG_DIR);
|
|
122
|
+
mkdirSync(dir, { recursive: true });
|
|
123
|
+
const configPath = join(dir, 'config.json');
|
|
124
|
+
const steps = [];
|
|
125
|
+
if (!existsSync(configPath)) {
|
|
126
|
+
writeFileSync(configPath, '{}\n');
|
|
127
|
+
steps.push(`Created ${CONFIG_DIR}/config.json (empty: every setting has a default).`);
|
|
128
|
+
}
|
|
129
|
+
// The index is a local cache; .remimem/memory.json and config.json stay committable.
|
|
130
|
+
const ignorePath = join(root, '.gitignore');
|
|
131
|
+
const entry = `${CONFIG_DIR}/index.db*`;
|
|
132
|
+
const ignore = existsSync(ignorePath) ? readFileSync(ignorePath, 'utf8') : '';
|
|
133
|
+
if (!ignore.split(/\r?\n/).includes(entry)) {
|
|
134
|
+
appendFileSync(ignorePath, `${ignore && !ignore.endsWith('\n') ? '\n' : ''}${entry}\n`);
|
|
135
|
+
steps.push(`Added ${entry} to .gitignore.`);
|
|
136
|
+
}
|
|
137
|
+
const provider = createProvider(loadConfig(root).embedding);
|
|
138
|
+
const privacy = provider && !provider.local
|
|
139
|
+
? `Privacy: embeddings are computed by ${provider.id}, so indexed code is sent to that service.`
|
|
140
|
+
: 'Privacy: everything runs on this machine. No code leaves it and there is no telemetry.';
|
|
141
|
+
const summary = await runIndex(root, options);
|
|
142
|
+
return [...steps, privacy, summary, '', clientConfigs()].join('\n');
|
|
143
|
+
}
|
|
144
|
+
function withStore(root, run) {
|
|
145
|
+
if (!existsSync(dbPath(root))) {
|
|
146
|
+
throw new StoreError('No index found in this directory; run `remimem index` first');
|
|
147
|
+
}
|
|
148
|
+
const store = new Store(dbPath(root));
|
|
149
|
+
let result;
|
|
150
|
+
try {
|
|
151
|
+
result = run(store);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
store.close();
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
if (result instanceof Promise)
|
|
158
|
+
return result.finally(() => store.close());
|
|
159
|
+
store.close();
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
/** One line describing an index run, shared by `index`, `init`, and `watch`. */
|
|
163
|
+
function describeRun(stats) {
|
|
164
|
+
return `Indexed ${stats.indexed} of ${stats.scanned} files (${stats.unchanged} unchanged, ${stats.deleted} removed) in ${stats.seconds.toFixed(2)}s.`;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* `remimem watch`: indexes once, then re-indexes whenever files change. Returns a function
|
|
168
|
+
* that stops watching.
|
|
169
|
+
*/
|
|
170
|
+
export async function runWatch(root, print) {
|
|
171
|
+
const config = loadConfig(root);
|
|
172
|
+
mkdirSync(join(root, CONFIG_DIR), { recursive: true });
|
|
173
|
+
const store = new Store(dbPath(root));
|
|
174
|
+
const provider = createProvider(config.embedding);
|
|
175
|
+
print(describeRun(await indexRepo(root, store, config, { provider })));
|
|
176
|
+
const watcher = startWatch(root, store, config, provider, (stats) => print(describeRun(stats)));
|
|
177
|
+
print(`Watching ${root} for changes. Press Ctrl+C to stop.`);
|
|
178
|
+
return async () => {
|
|
179
|
+
await watcher.close();
|
|
180
|
+
store.close();
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** `remimem stats`: queries served and tokens served against the estimated baseline. */
|
|
184
|
+
export function runStats(root) {
|
|
185
|
+
return withStore(root, (store) => formatStats(store));
|
|
186
|
+
}
|
|
187
|
+
/** `remimem debug symbol`: a symbol with its neighbors. */
|
|
188
|
+
export function runSymbol(root, name, options) {
|
|
189
|
+
return withStore(root, (store) => describeSymbol(store, name, options));
|
|
190
|
+
}
|
|
191
|
+
/** `remimem debug refs`: where a symbol is called, extended, used as a type, or imported. */
|
|
192
|
+
export function runRefs(root, name) {
|
|
193
|
+
return withStore(root, (store) => findReferences(store, name));
|
|
194
|
+
}
|
|
195
|
+
/** True when a Node.js version string such as "22.13.0" meets the minimum (22.13.0). */
|
|
196
|
+
export function nodeOk(version) {
|
|
197
|
+
const [major = 0, minor = 0] = version.split('.').map(Number);
|
|
198
|
+
return major > 22 || (major === 22 && minor >= 13);
|
|
199
|
+
}
|
|
200
|
+
/** `remimem doctor`: one line per check, and whether all of them passed. */
|
|
201
|
+
export async function runDoctor(root) {
|
|
202
|
+
const lines = [];
|
|
203
|
+
let ok = true;
|
|
204
|
+
const check = async (name, fix, run) => {
|
|
205
|
+
try {
|
|
206
|
+
lines.push(`${name}: ${await run()}`);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
ok = false;
|
|
210
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error;
|
|
211
|
+
lines.push(`${name}: failed (${String(cause)}). ${fix}`);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
await check('Node.js', 'Install Node.js 22.13.0 or newer.', async () => {
|
|
215
|
+
if (!nodeOk(process.versions.node))
|
|
216
|
+
throw new Error(`${process.versions.node} is too old`);
|
|
217
|
+
return `${process.versions.node} ok`;
|
|
218
|
+
});
|
|
219
|
+
for (const lang of LANGS) {
|
|
220
|
+
await check(`Grammar ${lang}`, 'Reinstall remimem.', async () => {
|
|
221
|
+
await parseSource(lang, '');
|
|
222
|
+
return 'ok';
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
await check('SQLite with FTS5 and sqlite-vec', 'Reinstall remimem.', async () => {
|
|
226
|
+
new Store(':memory:').close();
|
|
227
|
+
return 'ok';
|
|
228
|
+
});
|
|
229
|
+
await check('Embedding model', 'The first use downloads the model: check the network connection, or set "embedding": { "provider": "none" } in .remimem/config.json to work without it.', async () => {
|
|
230
|
+
const provider = createProvider(loadConfig(root).embedding);
|
|
231
|
+
if (!provider)
|
|
232
|
+
return 'off (keyword search only)';
|
|
233
|
+
const [vector] = await provider.embed(['remimem doctor'], 'query');
|
|
234
|
+
return `${provider.id} ok (${vector?.length} dimensions)`;
|
|
235
|
+
});
|
|
236
|
+
await check('Index', 'Run `remimem index --full` to rebuild it.', async () => {
|
|
237
|
+
if (!existsSync(dbPath(root)))
|
|
238
|
+
return 'none yet (run `remimem init` in the project)';
|
|
239
|
+
const store = new Store(dbPath(root));
|
|
240
|
+
try {
|
|
241
|
+
const counts = store.counts();
|
|
242
|
+
const pending = await pendingChanges(root, store, loadConfig(root));
|
|
243
|
+
const model = store.embeddingModel();
|
|
244
|
+
const missing = model ? counts.chunks - store.vectorCount() : 0;
|
|
245
|
+
return [
|
|
246
|
+
`${counts.files} files, ${counts.chunks} chunks`,
|
|
247
|
+
`${pending.changed + pending.added + pending.deleted} pending changes`,
|
|
248
|
+
model ? `${missing} chunks without a vector` : 'no vectors',
|
|
249
|
+
].join(', ');
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
store.close();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return { lines, ok };
|
|
256
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { RemimemError } from '../errors.js';
|
|
3
|
+
import { buildProgram } from './program.js';
|
|
4
|
+
// Exit quietly when the reader goes away, as in `remimem search x | head`.
|
|
5
|
+
process.stdout.on('error', (error) => {
|
|
6
|
+
if (error.code !== 'EPIPE')
|
|
7
|
+
throw error;
|
|
8
|
+
process.exit(0);
|
|
9
|
+
});
|
|
10
|
+
try {
|
|
11
|
+
await buildProgram().parseAsync();
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (!(error instanceof RemimemError))
|
|
15
|
+
throw error;
|
|
16
|
+
console.error(`error: ${error.message}`);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
}
|