open-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.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -0
  3. package/assets/brand/logo-lockup-dark.svg +14 -0
  4. package/assets/brand/logo-lockup.svg +14 -0
  5. package/assets/brand/logo.svg +9 -0
  6. package/bin/opencontextengine.mjs +64 -0
  7. package/docs/QUICKSTART.md +192 -0
  8. package/docs/RERANKER_API.md +32 -0
  9. package/package.json +81 -0
  10. package/requirements.txt +2 -0
  11. package/scripts/mcp-opencontextengine.mjs +37 -0
  12. package/scripts/retrieval-server.py +135 -0
  13. package/src/client.mjs +37 -0
  14. package/src/config.mjs +49 -0
  15. package/src/environment.mjs +10 -0
  16. package/src/eval/remote-models.mjs +70 -0
  17. package/src/mcp.mjs +58 -0
  18. package/src/retrieval/batched.py +220 -0
  19. package/src/retrieval/cascade.py +142 -0
  20. package/src/retrieval/engine.py +195 -0
  21. package/src/retrieval/entities.py +187 -0
  22. package/src/retrieval/languages/__init__.py +129 -0
  23. package/src/retrieval/languages/files.py +90 -0
  24. package/src/retrieval/languages/go.py +154 -0
  25. package/src/retrieval/languages/go_ast.go +204 -0
  26. package/src/retrieval/languages/go_types.go +169 -0
  27. package/src/retrieval/languages/python.py +113 -0
  28. package/src/retrieval/languages/schema.py +81 -0
  29. package/src/retrieval/languages/text.py +39 -0
  30. package/src/retrieval/languages/typescript.mjs +233 -0
  31. package/src/retrieval/languages/typescript.py +23 -0
  32. package/src/retrieval/live.py +273 -0
  33. package/src/retrieval/reranker.py +83 -0
  34. package/src/retrieval/routed.py +35 -0
  35. package/src/runtime.mjs +60 -0
  36. package/src/service.mjs +77 -0
  37. package/src/setup.mjs +66 -0
  38. package/src/workspaces.mjs +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AnnaSuSu
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,177 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="assets/brand/logo-lockup-dark.svg">
4
+ <img src="assets/brand/logo-lockup.svg" alt="OpenContextEngine" width="660">
5
+ </picture>
6
+ <p><strong>Precise code context for AI coding agents.</strong></p>
7
+ <p>Find related code across files. Follow its connections. Give your agent the evidence it needs.</p>
8
+ <p>
9
+ <a href="docs/BENCHMARKS.md#seven-method-comparison"><img src="https://img.shields.io/badge/dev_evidence_coverage-94.79%25-23875b?style=flat-square" alt="Development evidence coverage: 94.79%"></a>
10
+ <a href="docs/BENCHMARKS.md#seven-method-comparison"><img src="https://img.shields.io/badge/median_retrieval-1.73_s-23875b?style=flat-square" alt="Median retrieval: 1.73 seconds"></a>
11
+ <a href="docs/BENCHMARKS.md#engineering-validation"><img src="https://img.shields.io/badge/verified_tests-107-23875b?style=flat-square" alt="107 verified tests"></a>
12
+ <a href="docs/QUICKSTART.md"><img src="https://img.shields.io/badge/MCP-stdio-193c34?style=flat-square" alt="MCP over stdio"></a>
13
+ </p>
14
+ <p><a href="#quick-start">Quick start</a> · <a href="docs/BENCHMARKS.md">Benchmarks</a> · <a href="docs/QUICKSTART.md">MCP setup</a></p>
15
+ </div>
16
+
17
+ OpenContextEngine is a **self-hostable code context engine for AI coding agents**. Connect it to your agent through MCP to help it explore an unfamiliar codebase, locate implementations, and find the related code needed for a fix or feature.
18
+
19
+ It indexes your working directory and follows saved changes. Given a natural-language task, it combines semantic and keyword search, code relationships, and reranking to return relevant source snippets with file paths and line numbers, within a fixed context budget.
20
+
21
+ ## Why OpenContextEngine
22
+
23
+ - **Search beyond exact words.** Describe a behavior; retrieve its implementation and connected code across files.
24
+ - **Understand code structure.** Python, TypeScript, JavaScript, and Go adapters, plus text fallback for other languages, configuration, and scripts.
25
+ - **Stay current as you edit.** Saved changes, file deletions, and branch switches sync automatically. Unchanged embeddings are reused; incomplete updates never replace a complete index.
26
+ - **Work across projects through MCP.** Your agent supplies the project path; indexes start on demand and are reused. `search_code` retrieves evidence; `index_status` reports synchronization.
27
+
28
+ ## Measured results
29
+
30
+ ![Required evidence coverage and observed query time](assets/benchmarks/method-comparison.svg)
31
+
32
+ **94.79% required evidence coverage · 1.73 s median retrieval · 69/80 queries with complete evidence.** Seven engines, four repositories, the same 4,000-token output budget. OpenContextEngine retained the most required evidence in this internal development evaluation.
33
+
34
+ Measured with the optional batch rerank API. 40 source-derived tasks, each asked in Chinese and English. Coverage measures source evidence, not coding-agent success. Timings reflect native retrieval for open tools and SDK client calls for ACE. [Full comparison, configurations, and per-query results →](docs/eval/METHOD_COMPARISON.md)
35
+
36
+ ## Quick start
37
+
38
+ Requires **macOS or Linux**, Node.js 22.14+, Python 3.10+, Git, and configured embedding/reranking services. Go repositories also need Go 1.22+.
39
+
40
+ **Preparing the first npm release; not yet published.** Get the installation archive from the maintainer, then expand your client's guide. Model settings are shared across clients on the same machine.
41
+
42
+ <details>
43
+ <summary><strong>Codex — install, connect, and search</strong></summary>
44
+
45
+ **1. Install the CLI**
46
+
47
+ With Codex CLI already installed, run:
48
+
49
+ ```sh
50
+ npm install -g /path/to/open-context-engine-0.1.0.tgz
51
+ ```
52
+
53
+ **2. Configure your models**
54
+
55
+ ```sh
56
+ open-context-engine setup
57
+ ```
58
+
59
+ Enter your embedding and reranking base URLs, API keys, model names, and embedding dimensions. Setup installs isolated Python dependencies and saves your settings. The default reranker uses the ordinary `/rerank` API. [Endpoint examples →](docs/QUICKSTART.md#2-shared-model-configuration)
60
+
61
+ **3. Add the MCP server**
62
+
63
+ ```sh
64
+ codex mcp add open-context-engine -- open-context-engine mcp
65
+ codex mcp get open-context-engine
66
+ ```
67
+
68
+ The second command checks the saved configuration. These commands assume `open-context-engine` is on the client's `PATH`. For the desktop app or source installations, use the [absolute-path configuration](docs/QUICKSTART.md#client-setup-notes). Restart an already-running Codex client after adding the server.
69
+
70
+ **4. Search your project**
71
+
72
+ ```sh
73
+ cd /path/to/your-project
74
+ codex
75
+ ```
76
+
77
+ Ask:
78
+
79
+ > Use open-context-engine's search_code tool to explain this project's main functionality. Include the entry points and relevant file paths and line numbers.
80
+
81
+ Codex supplies the project's absolute path as `directory_path`. The first request starts indexing; if it is still building, ask Codex to check `index_status` and retry when ready. Later searches reuse the index, and saved changes update automatically.
82
+
83
+ [Codex MCP reference](https://developers.openai.com/codex/mcp)
84
+
85
+ </details>
86
+
87
+ <details>
88
+ <summary><strong>Claude Code — install, connect, and search</strong></summary>
89
+
90
+ **1. Install the CLI**
91
+
92
+ With Claude Code already installed, run:
93
+
94
+ ```sh
95
+ npm install -g /path/to/open-context-engine-0.1.0.tgz
96
+ ```
97
+
98
+ **2. Configure your models**
99
+
100
+ ```sh
101
+ open-context-engine setup
102
+ ```
103
+
104
+ Enter your embedding and reranking base URLs, API keys, model names, and embedding dimensions. Setup installs isolated Python dependencies and saves your settings. If you already completed setup for Codex, reuse those settings and skip this step. [Endpoint examples →](docs/QUICKSTART.md#2-shared-model-configuration)
105
+
106
+ **3. Add the MCP server**
107
+
108
+ ```sh
109
+ claude mcp add --transport stdio --scope user open-context-engine -- open-context-engine mcp
110
+ ```
111
+
112
+ User scope makes the server available across your projects. For a shared project configuration, run the command from that project and replace `--scope user` with `--scope project`. These commands assume `open-context-engine` is on the client's `PATH`; see [client setup notes](docs/QUICKSTART.md#client-setup-notes) for absolute paths. Restart an already-running Claude Code session after adding the server.
113
+
114
+ **4. Search your project**
115
+
116
+ ```sh
117
+ cd /path/to/your-project
118
+ claude
119
+ ```
120
+
121
+ Run `/mcp` to check the connection, then ask:
122
+
123
+ > Use open-context-engine's search_code tool to explain this project's main functionality. Include the entry points and relevant file paths and line numbers.
124
+
125
+ Claude supplies the project's absolute path as `directory_path`. The first request starts indexing; if it is still building, ask Claude to check `index_status` and retry when ready. Later searches reuse the index, and saved changes update automatically.
126
+
127
+ [Claude Code MCP reference](https://code.claude.com/docs/en/mcp)
128
+
129
+ </details>
130
+
131
+ <details>
132
+ <summary>Other MCP clients</summary>
133
+
134
+ [Install and run setup](docs/QUICKSTART.md#1-install), then use the configuration printed by `open-context-engine mcp-config` in your client's supported format. For clients that accept `mcpServers` JSON and can find the installed command on `PATH`:
135
+
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "open-context-engine": {
140
+ "command": "open-context-engine",
141
+ "args": ["mcp"]
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ Your agent supplies the current project's absolute path as `directory_path`. To pin one project, add `"--root", "/absolute/path/to/your-repository"` to `args`.
148
+
149
+ </details>
150
+
151
+ <details>
152
+ <summary>Run from source or build an internal package</summary>
153
+
154
+ ```sh
155
+ git clone https://github.com/AnnaSuSu/OpenContextEngine.git
156
+ cd OpenContextEngine
157
+ npm ci
158
+ node bin/opencontextengine.mjs setup
159
+ # Build an installable archive for internal testers:
160
+ npm pack
161
+ ```
162
+
163
+ Use the absolute Node and CLI paths printed by setup. [Client-specific configuration →](docs/QUICKSTART.md#client-setup-notes)
164
+
165
+ </details>
166
+
167
+ [Model configuration, troubleshooting, and update behavior →](docs/QUICKSTART.md)
168
+
169
+ Once published, install with `npm install -g open-context-engine`. Until then, use the archive above. [Release checklist](docs/RELEASING.md).
170
+
171
+ ## Explore
172
+
173
+ [Benchmark report](docs/BENCHMARKS.md) · [Raw evaluations](docs/eval/results) · [Retrieval engine](src/retrieval) · [Logo assets](assets/brand)
174
+
175
+ ## License
176
+
177
+ [MIT](LICENSE) © 2026 AnnaSuSu.
@@ -0,0 +1,14 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1320" height="240" viewBox="0 0 1320 240" role="img" aria-labelledby="title desc">
2
+ <title id="title">OpenContextEngine</title>
3
+ <desc id="desc">The OpenContextEngine bracket symbol beside the project name.</desc>
4
+ <g transform="translate(141 0)">
5
+ <g transform="translate(24 24) scale(.375)">
6
+ <g fill="none" stroke="#D9F2E5" stroke-width="56" stroke-linecap="square" stroke-linejoin="round">
7
+ <path d="M208 112H176L112 176V336L176 400H208"/>
8
+ <path d="M304 112H336L400 176V336L336 400H304"/>
9
+ </g>
10
+ <rect x="212" y="212" width="88" height="88" rx="12" fill="#35CE8D"/>
11
+ </g>
12
+ <text x="246" y="146" fill="#D9F2E5" font-family="Helvetica Neue, Helvetica, Arial, sans-serif" font-size="82" font-weight="600" letter-spacing="-3">OpenContextEngine</text>
13
+ </g>
14
+ </svg>
@@ -0,0 +1,14 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1320" height="240" viewBox="0 0 1320 240" role="img" aria-labelledby="title desc">
2
+ <title id="title">OpenContextEngine</title>
3
+ <desc id="desc">The OpenContextEngine bracket symbol beside the project name.</desc>
4
+ <g transform="translate(141 0)">
5
+ <g transform="translate(24 24) scale(.375)">
6
+ <g fill="none" stroke="#193C34" stroke-width="56" stroke-linecap="square" stroke-linejoin="round">
7
+ <path d="M208 112H176L112 176V336L176 400H208"/>
8
+ <path d="M304 112H336L400 176V336L336 400H304"/>
9
+ </g>
10
+ <rect x="212" y="212" width="88" height="88" rx="12" fill="#35CE8D"/>
11
+ </g>
12
+ <text x="246" y="146" fill="#193C34" font-family="Helvetica Neue, Helvetica, Arial, sans-serif" font-size="82" font-weight="600" letter-spacing="-3">OpenContextEngine</text>
13
+ </g>
14
+ </svg>
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512" role="img" aria-labelledby="title desc">
2
+ <title id="title">OpenContextEngine</title>
3
+ <desc id="desc">Two open, chamfered brackets surround a green code block.</desc>
4
+ <g fill="none" stroke="#193C34" stroke-width="56" stroke-linecap="square" stroke-linejoin="round">
5
+ <path d="M208 112H176L112 176V336L176 400H208"/>
6
+ <path d="M304 112H336L400 176V336L336 400H304"/>
7
+ </g>
8
+ <rect x="212" y="212" width="88" height="88" rx="12" fill="#35CE8D"/>
9
+ </svg>
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from 'node:util';
3
+ import { readFileSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { setup, validateModels } from '../src/setup.mjs';
6
+ import { loadEnvironment, configDirectory } from '../src/config.mjs';
7
+ import { verifyPython, run } from '../src/runtime.mjs';
8
+ import { serviceConfig } from '../src/service.mjs';
9
+
10
+ const help = `OpenContextEngine — repository context for AI coding agents
11
+
12
+ Usage:
13
+ open-context-engine setup [--python /path/to/python3] [--non-interactive]
14
+ open-context-engine mcp [--root /project] [--state /outside/index]
15
+ open-context-engine mcp --connect
16
+ open-context-engine mcp-config
17
+ open-context-engine doctor
18
+ open-context-engine --version
19
+
20
+ Setup installs isolated Python dependencies, saves shared model settings, and
21
+ prints MCP configuration. Without --root, your agent supplies directory_path.
22
+ Requires macOS/Linux, Node.js 22.14+, Python 3.10+, and Git.
23
+ `;
24
+ function mcpConfig() {
25
+ const env = process.env.OCE_CONFIG_HOME ? {OCE_CONFIG_HOME:configDirectory()} : undefined;
26
+ console.log(JSON.stringify({mcpServers:{'open-context-engine':{command:process.execPath,
27
+ args:[fileURLToPath(import.meta.url),'mcp'],...(env ? {env} : {})}}},null,2));
28
+ }
29
+ try {
30
+ const [command,...args] = process.argv.slice(2);
31
+ if (!command || command === '--help' || command === '-h' || args.includes('--help')) {
32
+ console.log(help);
33
+ } else if (command === '--version' || command === '-v') {
34
+ console.log(JSON.parse(readFileSync(new URL('../package.json',import.meta.url),'utf8')).version);
35
+ } else if (command === 'setup') {
36
+ const {values} = parseArgs({args,options:{python:{type:'string'},'non-interactive':{type:'boolean'}}});
37
+ await setup({python:values.python,nonInteractive:Boolean(values['non-interactive'])});
38
+ mcpConfig();
39
+ } else if (command === 'mcp-config' && args.length === 0) {
40
+ mcpConfig();
41
+ } else if (command === 'doctor' && args.length === 0) {
42
+ const env = loadEnvironment();
43
+ validateModels(env);
44
+ await run('git',['--version'],{timeout:10000});
45
+ const python = serviceConfig().python;
46
+ const version = await verifyPython(python,env);
47
+ console.log(`Model configuration valid. Python ${version}, NumPy, tiktoken, and Git are ready.`);
48
+ console.log('Endpoint authentication is checked during search. Go projects also require Go 1.22+.');
49
+ } else if (command === 'mcp') {
50
+ // Keep stdout exclusively for MCP messages. Setup remains a separate terminal command.
51
+ if (!args.includes('--connect')) {
52
+ validateModels(loadEnvironment());
53
+ await verifyPython(serviceConfig().python,loadEnvironment());
54
+ }
55
+ process.argv.splice(2,1);
56
+ await import('../scripts/mcp-opencontextengine.mjs');
57
+ } else {
58
+ throw new Error('Unknown command or arguments. Run open-context-engine --help');
59
+ }
60
+ } catch (error) {
61
+ process.stderr.write(`OpenContextEngine: ${error.message}\n`);
62
+ process.stderr.write('Run open-context-engine setup to configure models and install Python dependencies.\n');
63
+ process.exitCode = 1;
64
+ }
@@ -0,0 +1,192 @@
1
+ # Connect OpenContextEngine to your agent
2
+
3
+ OpenContextEngine runs a local repository index and calls configured model services for embeddings and reranking. Its MCP interface uses stdio. Currently supported hosts: **macOS and Linux**.
4
+
5
+ ## 1. Install
6
+
7
+ Requires Node.js 22.14+, Python 3.10+, and Git. Go source analysis also needs Go 1.22+ on `PATH`, or an explicit `OCE_GO_BINARY`.
8
+
9
+ **First npm release in preparation; not yet published.** Install the archive supplied by the maintainer:
10
+
11
+ ```sh
12
+ npm install -g /path/to/open-context-engine-0.1.0.tgz
13
+ open-context-engine setup
14
+ ```
15
+
16
+ `setup` asks for your embedding and reranking endpoints, keys, model names, and embedding dimensions. It creates a private Python virtual environment, installs NumPy and tiktoken, and preloads tokenizer data. No model weights are installed. API key input is not echoed. Use `--python /absolute/path/to/python3` to select a base interpreter.
17
+
18
+ You can also run the same setup from source:
19
+
20
+ ```sh
21
+ git clone https://github.com/AnnaSuSu/OpenContextEngine.git
22
+ cd OpenContextEngine
23
+ npm ci
24
+ node bin/opencontextengine.mjs setup
25
+ ```
26
+
27
+ After the first npm release, install with `npm install -g open-context-engine`, then run `open-context-engine setup`. Maintainers can build an archive with `npm pack`; see the [release checklist](https://github.com/AnnaSuSu/OpenContextEngine/blob/main/docs/RELEASING.md).
28
+
29
+ The CLI and package are named `open-context-engine`. The previous `opencontextengine` command remains an alias. Existing configuration and cache directories keep their paths, so saved keys and indexes are reused.
30
+
31
+ ## 2. Shared model configuration
32
+
33
+ Setup saves `~/.config/opencontextengine/config.json` with owner-only file permissions. All MCP clients running under the same user share these settings. Python environments live in the adjacent `runtimes/` directory. Use `OCE_CONFIG_HOME` to select a separate configuration directory; setup includes that override in its generated MCP configuration.
34
+
35
+ Configuration precedence is **process environment → saved user settings → source checkout `.env` defaults**. The `.env` of the project being searched is never loaded. Existing source installations using `.env` and `OCE_PYTHON` continue to work.
36
+
37
+ For automation, set the following environment variables and run `open-context-engine setup --non-interactive`:
38
+
39
+ ```dotenv
40
+ EMBEDDING_BASE_URL=https://your-embedding-service.example/v1
41
+ EMBEDDING_API_KEY=your-embedding-key
42
+ EMBEDDING_MODEL=Qwen3-Embedding-4B
43
+ OCE_EMBEDDING_DIMENSIONS=1024
44
+
45
+ RERANK_BASE_URL=https://your-reranker-service.example/v1
46
+ RERANK_API_KEY=your-reranker-key
47
+ RERANK_MODEL=Qwen3-Reranker-4B
48
+ OCE_RERANK_API=rerank
49
+ ```
50
+
51
+ The embedding service must implement `POST /v1/embeddings`. By default, the reranker uses the ordinary `/rerank` API: requests contain `model`, `query`, `documents`, and `top_n`; responses must return every requested document in `results`, with its original `index` and a finite `relevance_score` between 0 and 1. Results may arrive in relevance order. Set the reranker base URL to the part before `/rerank`: for example, `https://provider.example/v1`, `/v2`, or `https://provider.example` for an unversioned endpoint.
52
+
53
+ HTTPS is the default. For an explicitly trusted remote HTTP deployment, set `OCE_ALLOW_HTTP=1` before running `open-context-engine setup`; setup saves this choice in the shared configuration. HTTP transmits API keys and source text without encryption. Local model endpoints remain prohibited. Set `OCE_EMBEDDING_DIMENSIONS` to the service's actual output size (for example, `2560`); changing the provider or dimensions creates a new index generation and does not mix incompatible cached vectors.
54
+
55
+ OpenContextEngine groups the needed pairs by query, reuses scores within each search, and makes at most two concurrent rerank requests by default. Optional `OCE_RERANK_CONCURRENCY` (1–8, default 2) and `OCE_RERANK_MAX_DOCUMENTS` (1–1,024, default 128) control concurrency and documents per request. It requests all scores and rejects missing, duplicate, or invalid result indices; errors are surfaced without silently switching endpoints.
56
+
57
+ For the [optional benchmark reranker server](RERANKER_API.md), you can optionally set `OCE_RERANK_API=rerank-batch` to combine multiple queries into its custom `/rerank-batch` endpoint. The default `rerank` mode works with this server too. Qwen3-Embedding-4B / Qwen3-Reranker-4B are the evaluated models; the published seven-method benchmark used the custom batch mode. Other providers and models still need compatibility and quality validation, especially if they score documents jointly rather than independently. Changing document batch limits may then affect scores.
58
+
59
+ The launcher defaults to HTTPS model endpoints, with explicit HTTP opt-in and SSH/direct-worker transport options available in [the transport configuration](../src/eval/remote-models.mjs). It does not install or load model weights on the client. Repository fragments and queries are sent to the model endpoints you configure.
60
+
61
+ For internal testing, both model APIs can use an existing SSH connection. Keep the logical `EMBEDDING_BASE_URL` and `RERANK_BASE_URL` unchanged so the vector cache retains its provider identity. Start a loopback-only forward in a separate terminal (replace the example host and server ports):
62
+
63
+ ```sh
64
+ ssh -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
65
+ -L 127.0.0.1:43079:127.0.0.1:8079 \
66
+ -L 127.0.0.1:43078:127.0.0.1:8078 operator@model-host.example
67
+ ```
68
+
69
+ Then start the CLI with these overrides, or save them with `setup --non-interactive`:
70
+
71
+ ```dotenv
72
+ EMBEDDING_SSH_TUNNEL_URL=http://127.0.0.1:43079/v1
73
+ EMBEDDING_SSH_REMOTE=operator@model-host.example:22
74
+ RERANK_SSH_TUNNEL_URL=http://127.0.0.1:43078
75
+ RERANK_SSH_REMOTE=operator@model-host.example:22
76
+ ```
77
+
78
+ The rerank tunnel must preserve the configured base URL's path prefix (for example, `/v1` if required). Keep the SSH process running while using MCP. The CLI does not create SSH sessions or store SSH passwords, and a disconnected tunnel surfaces an error instead of falling back to public HTTP. Models continue to run on the remote server.
79
+
80
+ ## 3. Add the MCP server
81
+
82
+ Paste the MCP configuration printed by setup into your client, or print it again with `open-context-engine mcp-config`. It uses absolute Node and CLI paths so desktop clients do not need to find npm's global binary directory.
83
+
84
+ If your client already has `open-context-engine` on `PATH`, this shorter equivalent works:
85
+
86
+ ```json
87
+ {
88
+ "mcpServers": {
89
+ "open-context-engine": {
90
+ "command": "open-context-engine",
91
+ "args": ["mcp"]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ Use your client's equivalent configuration format. Configuration and dependency errors go to stderr; MCP stdout is reserved for protocol messages.
98
+
99
+ Without `--root`, the server uses **automatic workspace mode**. Your agent supplies the absolute project directory in `directory_path` on each tool call. No indexing starts until a project is requested; first access starts a repository worker and background indexing. Later calls reuse it. One MCP session can search multiple projects, each with an independent worker and persistent index. Workers stay active until the client disconnects, when all are stopped.
100
+
101
+ The server does not infer your editor's project from its own launch directory. Its tool instructions tell the agent to use the project path supplied by the host, or inspect the current project directory. Missing, relative, or invalid paths return an error. Symbolic links to the same directory share a worker. Supply the same project root consistently, rather than a different subdirectory on each call.
102
+
103
+ Example tool arguments (sent by your agent):
104
+
105
+ ```json
106
+ {"directory_path":"/absolute/path/to/your-repository","query":"Where are user sessions validated?"}
107
+ ```
108
+
109
+ To pin the server to one project instead, append `"--root", "/absolute/path/to/your-repository"` to `args`. In this mode `directory_path` may be omitted; a different project path is rejected. Existing fixed-project configurations continue to work.
110
+
111
+ | Tool | Purpose |
112
+ | --- | --- |
113
+ | `search_code` | Pass `directory_path` and describe the behavior in `query`. Returns source paths, line numbers, and relevant code; default budget: 4,000 tokens. |
114
+ | `index_status` | Pass `directory_path` to inspect indexing progress, active generation, vector reuse, and the latest update error. First access also starts that project's index. |
115
+
116
+ ### Client setup notes
117
+
118
+ Start with the expandable **Codex** or **Claude Code** guide in the [README](../README.md#quick-start). The CLI registration commands there assume the installed executable is on the client's `PATH`.
119
+
120
+ For desktop clients or source installations, run `open-context-engine mcp-config` (or `node bin/opencontextengine.mjs mcp-config` from the checkout). Use the absolute `command` and `args` values it prints. Codex uses TOML rather than the printed `mcpServers` JSON; add or update this entry in `~/.codex/config.toml`, replacing the example paths:
121
+
122
+ ```toml
123
+ [mcp_servers.open-context-engine]
124
+ command = "/absolute/path/to/node"
125
+ args = ["/absolute/path/to/bin/opencontextengine.mjs", "mcp"]
126
+ startup_timeout_sec = 30
127
+ tool_timeout_sec = 180
128
+ ```
129
+
130
+ For Claude Code, use those same paths with its registration command:
131
+
132
+ ```sh
133
+ claude mcp add --transport stdio --scope user open-context-engine -- /absolute/path/to/node /absolute/path/to/bin/opencontextengine.mjs mcp
134
+ ```
135
+
136
+ Quote paths that contain spaces. If the generated configuration includes `env` (for example, a custom `OCE_CONFIG_HOME`), preserve it: use `[mcp_servers.open-context-engine.env]` in Codex or `--env OCE_CONFIG_HOME=/absolute/config/path` before `--transport stdio` in the Claude command. Keep your model keys in the shared OpenContextEngine settings saved by setup. Restart the client after changing its configuration.
137
+
138
+ - **Command not found:** use the absolute paths above and confirm the Node executable still exists after a Node upgrade.
139
+ - **Tools missing:** check `codex mcp get open-context-engine` for the saved Codex entry, or `/mcp` inside Claude Code for connection status; restart the client after configuration changes.
140
+ - **First search is still indexing:** ask the agent to call `index_status` for the same project. Once it reports ready, retry `search_code`. Large repositories can take longer than a single tool call's timeout. If status reports an error, resolve that error before retrying.
141
+ - **Model configuration or authentication errors:** rerun `open-context-engine setup`. `open-context-engine doctor` checks local configuration and dependencies; an actual search checks access to the model APIs. If using SSH forwarding, keep the tunnel running.
142
+
143
+ Client references: [Codex MCP](https://developers.openai.com/codex/mcp) · [Claude Code MCP](https://code.claude.com/docs/en/mcp).
144
+
145
+ ## Updates & storage
146
+
147
+ Saved files are checked every second by default, with a 300 ms debounce. New files, deletions, renames, and branch changes update the index automatically. Embeddings are reused by model identity and actual input content. Structural analysis conservatively refreshes the affected language group to update references in unchanged files.
148
+
149
+ Search actively checks source hashes before retrieval and again before returning. It waits up to 30 seconds for synchronization (`freshnessWaitMs`, maximum 120 seconds). Failed updates, timeouts, or edits during retrieval produce explicit errors. Unsaved editor buffers are not indexed.
150
+
151
+ State is stored in `~/.cache/opencontextengine/<repository-path-hash>/`. Override it with `--state /outside/repository/index`: automatic mode creates a separate path-hash subdirectory for each project; fixed `--root` mode uses that exact state directory. Existing installations automatically reuse their previous cache location. One worker may write to a state directory at a time. Stop that worker and remove the directory to delete stored source and embeddings.
152
+
153
+ When model weights change under the same name, increment `OCE_EMBEDDING_REVISION`. A different provider, model name, or dimension count also invalidates vector reuse. Other models need separate compatibility and quality validation.
154
+
155
+ ## Share one worker across clients
156
+
157
+ This optional source-installation workflow shares a running worker, in addition to the shared model configuration available to all CLI installations. Set an `OCE_API_KEY` of at least 24 characters in the environment, then run from the checkout:
158
+
159
+ ```sh
160
+ npm run serve-retrieval -- --root /absolute/path/to/your-repository --port 23505
161
+ ```
162
+
163
+ Configure each MCP client to run `open-context-engine mcp --connect` (or `node scripts/mcp-opencontextengine.mjs --connect` from source), with `OCE_BASE_URL=http://127.0.0.1:23505` and the same `OCE_API_KEY`. This mode always uses the shared worker's configured project: omit `directory_path`. Closing a client leaves the shared worker running.
164
+
165
+ ## Check and upgrade
166
+
167
+ Run `open-context-engine doctor` to check model configuration, Python dependencies, tokenizer data, and Git. This does not send code to model providers; endpoint authentication is checked during actual search.
168
+
169
+ If upgrading from the old package named `opencontextengine`, first run `npm uninstall -g opencontextengine` to avoid a command-name conflict. This leaves your saved model settings and indexes intact.
170
+
171
+ For an internal upgrade, install the new archive and rerun setup:
172
+
173
+ ```sh
174
+ npm install -g /path/to/new-open-context-engine.tgz
175
+ open-context-engine setup
176
+ ```
177
+
178
+ Press Enter to retain saved settings. Setup reuses a healthy managed Python runtime when its dependency requirements match; otherwise it builds a new environment before changing the saved configuration. Failed dependency installation preserves the previous settings and runtime. Old runtimes remain available for rollback. When migrating from the old package name, replace the client entry with the configuration printed by setup: its absolute installation path has changed. Restart the MCP client after an upgrade. Project indexes remain outside the package directory and continue to reuse compatible embeddings.
179
+
180
+ First-time setup requires network access to npm/PyPI and tokenizer data. If Python is missing or lacks `venv`/`pip`, install Python 3.10+ with those components, then rerun setup. The CLI does not install system Node, Python, Git, or Go.
181
+
182
+ ## Internal testing checklist
183
+
184
+ 1. Install the supplied tarball on macOS or Linux and run setup with your model endpoints.
185
+ 2. Paste the generated MCP configuration into your client, restart it, and search a small project.
186
+ 3. Save an edit, add a file, and delete a file; verify search returns current source.
187
+ 4. Switch to another project and back; verify the results belong to the requested project.
188
+ 5. Restart the client and reinstall the archive; verify model settings and compatible indexes are retained.
189
+
190
+ For issues, include the CLI version, operating system, client name, and the error message. Keep API keys and private source code out of reports.
191
+
192
+ [Benchmark & test report](BENCHMARKS.md) · [Detailed update design](LIVE_INDEX.md) · [MCP implementation](../src/mcp.mjs)
@@ -0,0 +1,32 @@
1
+ # Optional benchmark reranker
2
+
3
+ OpenContextEngine calls model services over HTTP. Normal installation does not require running a GPU model server from this repository; configure your own embedding and reranking endpoints as described in [Quick start](QUICKSTART.md).
4
+
5
+ The published benchmarks used Qwen3-Reranker-4B with an optional batch API. Its [reference server](../scripts/benchmarks/reranker-server.py) is retained with the benchmark tools so the scoring implementation remains inspectable. It loads model weights and runs only on a separately configured Linux CUDA host with `OCE_REMOTE_MODEL_HOST=1`.
6
+
7
+ ## API modes
8
+
9
+ | Mode | Endpoint | Request | Response |
10
+ | --- | --- | --- | --- |
11
+ | Default | `POST /v1/rerank` | `model`, `query`, `documents`, `top_n` | `results` with original document `index` and `relevance_score` |
12
+ | Optional batch | `POST /v1/rerank-batch` | `model`, `queries`, `documents`, `pairs` of query/document indices | `results` with original pair `index`, `query_index`, `document_index`, and `relevance_score` |
13
+
14
+ Both endpoints require `Authorization: Bearer <key>`. Scores are finite values between 0 and 1. The batch implementation shares inference across requested pairs; it does not generate an answer. The published seven-method comparison used `OCE_RERANK_API=rerank-batch`; ordinary services use `OCE_RERANK_API=rerank`.
15
+
16
+ The reference server exposes unauthenticated readiness through `GET /healthz` and authenticated model metadata through `GET /v1/models`. It reports truncation and rejects invalid inputs. Its source defines input, batch, body-size, concurrency, and timeout limits.
17
+
18
+ ## Reference environment
19
+
20
+ The recorded benchmark deployment used Python 3.12, PyTorch 2.7.1 with CUDA 12.8, Transformers 4.57.6, and BF16 inference. The server additionally imports FastAPI and Pydantic and needs an ASGI runner such as Uvicorn. These model-server dependencies are separate from the client requirements.
21
+
22
+ The operator supplies `RERANK_MODEL_DIR` pointing to pre-provisioned Qwen3-Reranker-4B weights and `RERANK_API_KEY` with at least 24 characters. Loading is local-only with remote model code disabled. Optional batch settings are `RERANK_MAX_BATCH` and `RERANK_BATCH_TOKEN_BUDGET`.
23
+
24
+ On that Linux model host, from this repository's root:
25
+
26
+ ```sh
27
+ # Set the model directory and secret in the server's environment first.
28
+ OCE_REMOTE_MODEL_HOST=1 python -m uvicorn reranker-server:app \
29
+ --app-dir scripts/benchmarks --host 127.0.0.1 --port 8000
30
+ ```
31
+
32
+ Use an HTTPS proxy or explicitly configured secure transport for remote clients. Personal service addresses, Supervisor configuration, and deployment logs are not part of the public example. No deployment or model download is performed by installing OpenContextEngine.
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "open-context-engine",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=22.14"
7
+ },
8
+ "scripts": {
9
+ "test": "node --test tests/*.test.mjs",
10
+ "prepare-django": "node scripts/prepare-django.mjs",
11
+ "ace-django": "node scripts/ace-django.mjs",
12
+ "score-django": "node scripts/score-django.mjs",
13
+ "baseline": "node scripts/run-baseline.mjs",
14
+ "search": "node scripts/search-opencontextengine.mjs",
15
+ "serve-retrieval": "node scripts/serve-opencontextengine.mjs",
16
+ "benchmark-service": "node scripts/benchmark-service.mjs",
17
+ "mcp": "node scripts/mcp-opencontextengine.mjs"
18
+ },
19
+ "dependencies": {
20
+ "@modelcontextprotocol/sdk": "1.32.0",
21
+ "typescript": "5.9.3",
22
+ "zod": "4.6.5"
23
+ },
24
+ "description": "Live code context for AI coding agents, with automatic workspaces and MCP.",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/AnnaSuSu/OpenContextEngine.git"
28
+ },
29
+ "homepage": "https://github.com/AnnaSuSu/OpenContextEngine#readme",
30
+ "bin": {
31
+ "open-context-engine": "bin/opencontextengine.mjs",
32
+ "opencontextengine": "bin/opencontextengine.mjs"
33
+ },
34
+ "os": [
35
+ "darwin",
36
+ "linux"
37
+ ],
38
+ "files": [
39
+ "bin/",
40
+ "src/config.mjs",
41
+ "src/environment.mjs",
42
+ "src/client.mjs",
43
+ "src/service.mjs",
44
+ "src/workspaces.mjs",
45
+ "src/mcp.mjs",
46
+ "src/runtime.mjs",
47
+ "src/setup.mjs",
48
+ "src/eval/remote-models.mjs",
49
+ "src/retrieval/**/*.py",
50
+ "src/retrieval/**/*.mjs",
51
+ "src/retrieval/**/*.go",
52
+ "scripts/mcp-opencontextengine.mjs",
53
+ "scripts/retrieval-server.py",
54
+ "requirements.txt",
55
+ "docs/QUICKSTART.md",
56
+ "assets/brand/*.svg",
57
+ "docs/RERANKER_API.md"
58
+ ],
59
+ "devDependencies": {
60
+ "@augmentcode/auggie-sdk": "0.2.0",
61
+ "@openai/codex-sdk": "0.160.0",
62
+ "js-tiktoken": "1.0.21"
63
+ },
64
+ "license": "MIT",
65
+ "author": "AnnaSuSu",
66
+ "keywords": [
67
+ "mcp",
68
+ "code-search",
69
+ "code-context",
70
+ "codex",
71
+ "claude-code",
72
+ "retrieval"
73
+ ],
74
+ "bugs": {
75
+ "url": "https://github.com/AnnaSuSu/OpenContextEngine/issues"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public",
79
+ "registry": "https://registry.npmjs.org/"
80
+ }
81
+ }
@@ -0,0 +1,2 @@
1
+ numpy>=2.2,<3
2
+ tiktoken>=0.9,<1