bgts-context-engine 0.1.0__tar.gz

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 (117) hide show
  1. bgts_context_engine-0.1.0/CHANGELOG.md +33 -0
  2. bgts_context_engine-0.1.0/LICENSE +21 -0
  3. bgts_context_engine-0.1.0/MANIFEST.in +15 -0
  4. bgts_context_engine-0.1.0/PKG-INFO +361 -0
  5. bgts_context_engine-0.1.0/README.md +308 -0
  6. bgts_context_engine-0.1.0/README.tr.md +318 -0
  7. bgts_context_engine-0.1.0/pyproject.toml +123 -0
  8. bgts_context_engine-0.1.0/setup.cfg +4 -0
  9. bgts_context_engine-0.1.0/src/bce/__init__.py +8 -0
  10. bgts_context_engine-0.1.0/src/bce/api/__init__.py +6 -0
  11. bgts_context_engine-0.1.0/src/bce/api/mcp/__init__.py +11 -0
  12. bgts_context_engine-0.1.0/src/bce/api/mcp/server.py +61 -0
  13. bgts_context_engine-0.1.0/src/bce/api/mcp/tools.py +262 -0
  14. bgts_context_engine-0.1.0/src/bce/api/rest/__init__.py +11 -0
  15. bgts_context_engine-0.1.0/src/bce/api/rest/app.py +239 -0
  16. bgts_context_engine-0.1.0/src/bce/api/rest/deps.py +67 -0
  17. bgts_context_engine-0.1.0/src/bce/api/rest/routes.py +581 -0
  18. bgts_context_engine-0.1.0/src/bce/api/rest/schemas.py +130 -0
  19. bgts_context_engine-0.1.0/src/bce/api/rest/static/assets/index-DrLRaTMU.css +1 -0
  20. bgts_context_engine-0.1.0/src/bce/api/rest/static/assets/index-RAztiMtn.js +322 -0
  21. bgts_context_engine-0.1.0/src/bce/api/rest/static/favicon.svg +17 -0
  22. bgts_context_engine-0.1.0/src/bce/api/rest/static/index.html +24 -0
  23. bgts_context_engine-0.1.0/src/bce/api/rest/ui/__init__.py +18 -0
  24. bgts_context_engine-0.1.0/src/bce/api/rest/ui/queries.py +308 -0
  25. bgts_context_engine-0.1.0/src/bce/api/rest/ui/router.py +156 -0
  26. bgts_context_engine-0.1.0/src/bce/api/rest/ui/schemas.py +138 -0
  27. bgts_context_engine-0.1.0/src/bce/api/rest/ui/trace.py +300 -0
  28. bgts_context_engine-0.1.0/src/bce/bench/__init__.py +17 -0
  29. bgts_context_engine-0.1.0/src/bce/bench/runner.py +226 -0
  30. bgts_context_engine-0.1.0/src/bce/cli.py +401 -0
  31. bgts_context_engine-0.1.0/src/bce/config.py +97 -0
  32. bgts_context_engine-0.1.0/src/bce/core/__init__.py +1 -0
  33. bgts_context_engine-0.1.0/src/bce/core/assembler/__init__.py +10 -0
  34. bgts_context_engine-0.1.0/src/bce/core/assembler/assembler.py +103 -0
  35. bgts_context_engine-0.1.0/src/bce/core/auth/__init__.py +10 -0
  36. bgts_context_engine-0.1.0/src/bce/core/auth/scope.py +74 -0
  37. bgts_context_engine-0.1.0/src/bce/core/coverage/__init__.py +14 -0
  38. bgts_context_engine-0.1.0/src/bce/core/coverage/confidence.py +142 -0
  39. bgts_context_engine-0.1.0/src/bce/core/i18n/__init__.py +12 -0
  40. bgts_context_engine-0.1.0/src/bce/core/i18n/catalogs/en.json +37 -0
  41. bgts_context_engine-0.1.0/src/bce/core/i18n/catalogs/tr.json +37 -0
  42. bgts_context_engine-0.1.0/src/bce/core/i18n/locale.py +63 -0
  43. bgts_context_engine-0.1.0/src/bce/core/i18n/translator.py +70 -0
  44. bgts_context_engine-0.1.0/src/bce/core/logging.py +101 -0
  45. bgts_context_engine-0.1.0/src/bce/core/orchestrator/__init__.py +17 -0
  46. bgts_context_engine-0.1.0/src/bce/core/orchestrator/anchors.py +119 -0
  47. bgts_context_engine-0.1.0/src/bce/core/orchestrator/expand.py +167 -0
  48. bgts_context_engine-0.1.0/src/bce/core/orchestrator/orchestrator.py +77 -0
  49. bgts_context_engine-0.1.0/src/bce/core/scoring/__init__.py +21 -0
  50. bgts_context_engine-0.1.0/src/bce/core/scoring/engine.py +106 -0
  51. bgts_context_engine-0.1.0/src/bce/domain/__init__.py +35 -0
  52. bgts_context_engine-0.1.0/src/bce/domain/enums.py +96 -0
  53. bgts_context_engine-0.1.0/src/bce/domain/models.py +199 -0
  54. bgts_context_engine-0.1.0/src/bce/indexing/__init__.py +1 -0
  55. bgts_context_engine-0.1.0/src/bce/indexing/embedder/__init__.py +11 -0
  56. bgts_context_engine-0.1.0/src/bce/indexing/embedder/embedder.py +75 -0
  57. bgts_context_engine-0.1.0/src/bce/indexing/embedder/encoder.py +151 -0
  58. bgts_context_engine-0.1.0/src/bce/indexing/extractor/__init__.py +5 -0
  59. bgts_context_engine-0.1.0/src/bce/indexing/extractor/bridges.py +149 -0
  60. bgts_context_engine-0.1.0/src/bce/indexing/extractor/designnote.py +105 -0
  61. bgts_context_engine-0.1.0/src/bce/indexing/extractor/extractor.py +118 -0
  62. bgts_context_engine-0.1.0/src/bce/indexing/extractor/routes.py +69 -0
  63. bgts_context_engine-0.1.0/src/bce/indexing/gitsync/__init__.py +36 -0
  64. bgts_context_engine-0.1.0/src/bce/indexing/gitsync/bitbucket.py +73 -0
  65. bgts_context_engine-0.1.0/src/bce/indexing/gitsync/local.py +129 -0
  66. bgts_context_engine-0.1.0/src/bce/indexing/gitsync/remote.py +149 -0
  67. bgts_context_engine-0.1.0/src/bce/indexing/indexer.py +471 -0
  68. bgts_context_engine-0.1.0/src/bce/indexing/linker/__init__.py +11 -0
  69. bgts_context_engine-0.1.0/src/bce/indexing/linker/linker.py +325 -0
  70. bgts_context_engine-0.1.0/src/bce/indexing/parser/__init__.py +6 -0
  71. bgts_context_engine-0.1.0/src/bce/indexing/parser/_treesitter.py +58 -0
  72. bgts_context_engine-0.1.0/src/bce/indexing/parser/base.py +77 -0
  73. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/__init__.py +1 -0
  74. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/csharp_provider.py +564 -0
  75. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/go_provider.py +420 -0
  76. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/java_provider.py +511 -0
  77. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/jsts_provider.py +764 -0
  78. bgts_context_engine-0.1.0/src/bce/indexing/parser/languages/python_provider.py +677 -0
  79. bgts_context_engine-0.1.0/src/bce/indexing/parser/registry.py +81 -0
  80. bgts_context_engine-0.1.0/src/bce/indexing/parser/scip/__init__.py +27 -0
  81. bgts_context_engine-0.1.0/src/bce/indexing/parser/scip/resolver.py +211 -0
  82. bgts_context_engine-0.1.0/src/bce/indexing/parser/symbol_id.py +73 -0
  83. bgts_context_engine-0.1.0/src/bce/indexing/upserter/__init__.py +5 -0
  84. bgts_context_engine-0.1.0/src/bce/indexing/upserter/upserter.py +40 -0
  85. bgts_context_engine-0.1.0/src/bce/jobs/__init__.py +30 -0
  86. bgts_context_engine-0.1.0/src/bce/jobs/store.py +156 -0
  87. bgts_context_engine-0.1.0/src/bce/jobs/worker.py +129 -0
  88. bgts_context_engine-0.1.0/src/bce/storage/__init__.py +1 -0
  89. bgts_context_engine-0.1.0/src/bce/storage/graph/__init__.py +11 -0
  90. bgts_context_engine-0.1.0/src/bce/storage/graph/client.py +85 -0
  91. bgts_context_engine-0.1.0/src/bce/storage/graph/repository.py +474 -0
  92. bgts_context_engine-0.1.0/src/bce/storage/relational/__init__.py +1 -0
  93. bgts_context_engine-0.1.0/src/bce/storage/relational/db.py +37 -0
  94. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0001_extensions_graph.sql +21 -0
  95. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0002_relational.sql +59 -0
  96. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0003_vector.sql +20 -0
  97. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0004_rls.sql +36 -0
  98. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0005_embeddings_dim.sql +14 -0
  99. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0006_fts.sql +26 -0
  100. bgts_context_engine-0.1.0/src/bce/storage/relational/migrations/0007_jobs.sql +17 -0
  101. bgts_context_engine-0.1.0/src/bce/storage/relational/migrator.py +139 -0
  102. bgts_context_engine-0.1.0/src/bce/storage/relational/queries.py +63 -0
  103. bgts_context_engine-0.1.0/src/bce/storage/vector/__init__.py +10 -0
  104. bgts_context_engine-0.1.0/src/bce/storage/vector/store.py +110 -0
  105. bgts_context_engine-0.1.0/src/bce/tools/__init__.py +6 -0
  106. bgts_context_engine-0.1.0/src/bce/tools/layer1/__init__.py +19 -0
  107. bgts_context_engine-0.1.0/src/bce/tools/layer1/primitives.py +222 -0
  108. bgts_context_engine-0.1.0/src/bce/tools/layer2/__init__.py +10 -0
  109. bgts_context_engine-0.1.0/src/bce/tools/layer2/search.py +277 -0
  110. bgts_context_engine-0.1.0/src/bce/tools/layer3/__init__.py +22 -0
  111. bgts_context_engine-0.1.0/src/bce/tools/layer3/orchestration.py +488 -0
  112. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/PKG-INFO +361 -0
  113. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/SOURCES.txt +115 -0
  114. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/dependency_links.txt +1 -0
  115. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/entry_points.txt +2 -0
  116. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/requires.txt +28 -0
  117. bgts_context_engine-0.1.0/src/bgts_context_engine.egg-info/top_level.txt +1 -0
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this
6
+ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-09-08
11
+
12
+ First public release.
13
+
14
+ ### Added
15
+
16
+ - Deterministic retrieval pipeline: anchor discovery, graph expansion, scoring, narrowing
17
+ and context assembly, with coverage and confidence reporting.
18
+ - Code graph over PostgreSQL with Apache AGE and pgvector in a single database. Layer-3
19
+ results are filtered per user against the `scopes` table, resolved from the
20
+ `X-BCE-User` header.
21
+ - Tree-sitter indexing for Python, JavaScript and TypeScript, with optional grammars for
22
+ Java, C# and Go. Incremental re-indexing driven by `git diff`.
23
+ - Layer 1, 2 and 3 tool surfaces exposed over both REST and MCP.
24
+ - Web interface at `/ui`: a graph explorer and a player that replays each pipeline stage
25
+ for a given task. Ships inside the wheel; English by default with a Turkish catalog.
26
+ - `bce` command line interface: `migrate`, `index`, `index-remote`, `reindex`, `bench`,
27
+ `resolve-symbol`, `find-references`, `languages`, `serve` and `serve-mcp`.
28
+ - Benchmark harness reporting latency, recall, precision and determinism.
29
+ - Docker Compose deployment with PostgreSQL, Apache AGE and pgvector preconfigured.
30
+ - `server.json` manifest describing the stdio server for the official MCP registry.
31
+
32
+ [Unreleased]: https://github.com/bgts-ai/bgts-context-engine/compare/v0.1.0...HEAD
33
+ [0.1.0]: https://github.com/bgts-ai/bgts-context-engine/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BilgeAdam Technology
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.
@@ -0,0 +1,15 @@
1
+ include LICENSE
2
+ include README.md
3
+ include README.tr.md
4
+ include CHANGELOG.md
5
+ recursive-include src/bce/core/i18n/catalogs *.json
6
+ recursive-include src/bce/storage/relational/migrations *.sql
7
+
8
+ # Compiled frontend, vendored by scripts/build_ui.py before a release build.
9
+ recursive-include src/bce/api/rest/static *
10
+
11
+ prune tests
12
+ prune web
13
+ prune deploy
14
+ prune docs
15
+ prune scripts
@@ -0,0 +1,361 @@
1
+ Metadata-Version: 2.4
2
+ Name: bgts-context-engine
3
+ Version: 0.1.0
4
+ Summary: Deterministic code-graph context engine for AI coding agents - PostgreSQL, Apache AGE and pgvector, over MCP and REST
5
+ Author: Oğuz Öztürk, Enes İyidil
6
+ Maintainer: BilgeAdam Technology
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/bgts-ai/bgts-context-engine
9
+ Project-URL: Documentation, https://github.com/bgts-ai/bgts-context-engine/tree/main/docs
10
+ Project-URL: Repository, https://github.com/bgts-ai/bgts-context-engine
11
+ Project-URL: Issues, https://github.com/bgts-ai/bgts-context-engine/issues
12
+ Project-URL: Changelog, https://github.com/bgts-ai/bgts-context-engine/blob/main/CHANGELOG.md
13
+ Keywords: mcp,mcp-server,ai-agents,context-engineering,code-graph,code-search,codebase-indexing,rag,tree-sitter,apache-age,pgvector,postgresql,static-analysis,developer-tools
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Software Development :: Quality Assurance
23
+ Classifier: Topic :: Text Processing :: Indexing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: fastapi>=0.110
29
+ Requires-Dist: uvicorn[standard]>=0.29
30
+ Requires-Dist: pydantic>=2.6
31
+ Requires-Dist: pydantic-settings>=2.2
32
+ Requires-Dist: psycopg[binary,pool]>=3.1
33
+ Requires-Dist: pgvector>=0.2.5
34
+ Requires-Dist: typer>=0.12
35
+ Requires-Dist: tree-sitter>=0.21
36
+ Requires-Dist: tree-sitter-python>=0.21
37
+ Requires-Dist: tree-sitter-javascript>=0.21
38
+ Requires-Dist: tree-sitter-typescript>=0.21
39
+ Provides-Extra: dev
40
+ Requires-Dist: pytest>=8.0; extra == "dev"
41
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
42
+ Requires-Dist: ruff>=0.4; extra == "dev"
43
+ Requires-Dist: httpx>=0.27; extra == "dev"
44
+ Provides-Extra: mcp
45
+ Requires-Dist: mcp>=1.0; extra == "mcp"
46
+ Provides-Extra: embed
47
+ Requires-Dist: voyageai>=0.3; extra == "embed"
48
+ Provides-Extra: langs
49
+ Requires-Dist: tree-sitter-java>=0.21; extra == "langs"
50
+ Requires-Dist: tree-sitter-c-sharp>=0.21; extra == "langs"
51
+ Requires-Dist: tree-sitter-go>=0.21; extra == "langs"
52
+ Dynamic: license-file
53
+
54
+ <!-- mcp-name: io.github.bgts-ai/bgts-context-engine -->
55
+
56
+ <div align="center">
57
+
58
+ <img src="docs/assets/social-preview.png" alt="BGTS Context Engine" width="820">
59
+
60
+ **Deterministic code-graph context for AI coding agents.**
61
+
62
+ Ask *"why does the login timeout fire on the meeting webhook?"* and get the eight symbols
63
+ that actually answer it — ranked, budgeted, and reproducible.
64
+
65
+ [![PyPI](https://img.shields.io/pypi/v/bgts-context-engine.svg)](https://pypi.org/project/bgts-context-engine/)
66
+ [![Python](https://img.shields.io/pypi/pyversions/bgts-context-engine.svg)](https://pypi.org/project/bgts-context-engine/)
67
+ [![CI](https://github.com/bgts-ai/bgts-context-engine/actions/workflows/ci.yml/badge.svg)](https://github.com/bgts-ai/bgts-context-engine/actions/workflows/ci.yml)
68
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
69
+ [![MCP](https://img.shields.io/badge/MCP-compatible-000000.svg)](docs/mcp.md)
70
+ [![Stars](https://img.shields.io/github/stars/bgts-ai/bgts-context-engine?style=flat&logo=github)](https://github.com/bgts-ai/bgts-context-engine/stargazers)
71
+
72
+ [Quick start](#quick-start) · [Use it from your agent](#use-it-from-your-agent) · [How it works](#how-it-works) · [Documentation](#documentation) · [Türkçe](README.tr.md)
73
+
74
+ </div>
75
+
76
+ ---
77
+
78
+ ## Why this exists
79
+
80
+ An agent working on an unfamiliar repository has to decide what to read before it can
81
+ decide what to change. The usual answer is embedding search over chunked files. It is cheap
82
+ to build and wrong in a specific way: it returns text that *reads* like the question rather
83
+ than code that *participates* in the behaviour. Ask about a login timeout and you get the
84
+ five files that mention timeouts, not the one function that sets it and the three callers
85
+ that break when you change it.
86
+
87
+ That information is structural, and it has an exact answer. `handleLogin` calls
88
+ `refreshSession`, which reads `SESSION_TTL`, which is written in exactly one place. That is
89
+ a graph walk.
90
+
91
+ BGTS Context Engine indexes your repositories into that graph — symbols, calls,
92
+ references, type hierarchies, HTTP routes, cross-language bridges — and answers questions
93
+ by walking it. Embeddings are used in one place only: finding entry points when the task
94
+ text names nothing recognisable. They never affect ranking.
95
+
96
+ **The same task text, against the same commit, returns the same context pack.** No model in
97
+ the retrieval path, no clock, no randomness. When an agent makes a bad change you can
98
+ replay exactly what it was told, find the stage that surfaced the wrong symbol, and fix
99
+ that stage.
100
+
101
+ ## Quick start
102
+
103
+ ```bash
104
+ # 1. PostgreSQL 16 with Apache AGE + pgvector, in one database
105
+ docker compose -f deploy/docker-compose.yml up -d
106
+
107
+ # 2. Install and migrate
108
+ pip install bgts-context-engine
109
+ cp .env.example .env
110
+ bce migrate
111
+
112
+ # 3. Index something
113
+ bce index --repo /path/to/your/repo --name my-service
114
+
115
+ # 4. Ask
116
+ bce context --task "fix the login timeout in the meeting webhook"
117
+ ```
118
+
119
+ Then serve it:
120
+
121
+ ```bash
122
+ bce serve # REST at :8000/docs, web UI at :8000/ui/
123
+ bce serve-mcp # MCP over stdio, for agents
124
+ ```
125
+
126
+ ## Use it from your agent
127
+
128
+ The MCP surface is behind the `mcp` extra: `pip install "bgts-context-engine[mcp]"`. It
129
+ speaks stdio, so every MCP client configures it the same way — `bce serve-mcp`, plus the
130
+ database connection in the environment.
131
+
132
+ **Cursor** — `.cursor/mcp.json` in the project, or `~/.cursor/mcp.json` for every project:
133
+
134
+ ```json
135
+ {
136
+ "mcpServers": {
137
+ "bgts-context-engine": {
138
+ "command": "bce",
139
+ "args": ["serve-mcp"],
140
+ "env": { "BCE_DB_HOST": "localhost", "BCE_DB_NAME": "bce" }
141
+ }
142
+ }
143
+ }
144
+ ```
145
+
146
+ **Claude Code** — one command:
147
+
148
+ ```bash
149
+ claude mcp add bgts-context-engine --env BCE_DB_HOST=localhost -- bce serve-mcp
150
+ ```
151
+
152
+ **VS Code** — `.vscode/mcp.json`:
153
+
154
+ ```json
155
+ {
156
+ "servers": {
157
+ "bgts-context-engine": { "type": "stdio", "command": "bce", "args": ["serve-mcp"] }
158
+ }
159
+ }
160
+ ```
161
+
162
+ **Claude Desktop** — same block as Cursor, in `claude_desktop_config.json`.
163
+
164
+ Without a global install, `uvx --from "bgts-context-engine[mcp]" bce serve-mcp` works as the
165
+ `command` anywhere above.
166
+
167
+ Then ask your agent something that needs the repository rather than the file you have open:
168
+ *"what breaks if I change the session TTL?"* The agent calls `get_context_for_task`, and the
169
+ fourteen tools in [docs/mcp.md](docs/mcp.md) let it drill from there — exact callers, type
170
+ hierarchy, route handlers — without guessing at file names.
171
+
172
+ ## What comes back
173
+
174
+ Not a list of file paths. A ranked pack, with the reasoning attached:
175
+
176
+ ```json
177
+ {
178
+ "anchors": {
179
+ "python::api::webhooks::handle_meeting_webhook#a3f1": ["explicit", "lexical"],
180
+ "python::auth::session::refresh_session#88c2": ["lexical", "semantic"]
181
+ },
182
+ "context": {
183
+ "items": [
184
+ { "symbol_id": "...refresh_session#88c2", "detail_level": "full",
185
+ "graph_distance": 0, "score": 11.42, "tokens": 214, "content": "def refresh_session(...)" },
186
+ { "symbol_id": "...SESSION_TTL#4b0d", "detail_level": "signature",
187
+ "graph_distance": 2, "score": 6.10, "tokens": 31, "content": "SESSION_TTL: int" }
188
+ ],
189
+ "used_tokens": 2913, "budget": 4000, "included": 8, "skipped": 0
190
+ },
191
+ "coverage": {
192
+ "anchor_source_count": 3, "connected_component_ratio": 0.875,
193
+ "top_candidate_margin": 1.84, "orphan_ratio": 0.0,
194
+ "touches_god_node": false, "commit_mismatch": false,
195
+ "confidence": "high"
196
+ }
197
+ }
198
+ ```
199
+
200
+ Three things here that a vector store cannot give you:
201
+
202
+ **`anchors`** says *why* the engine looked where it did, and which independent sources
203
+ agreed. Three sources agreeing is usually right; one is a guess.
204
+
205
+ **`coverage`** is a trust report. `confidence: "low"` means the engine found something but
206
+ could not corroborate it — the moment for an agent to ask a follow-up question instead of
207
+ editing. `commit_mismatch` means the index is behind your working tree.
208
+
209
+ **`detail_level`** falls off with graph distance: the symbol you are changing arrives in
210
+ full, its neighbours as signatures, the outer ring as `name @ file:line`. That is how eight
211
+ genuinely relevant symbols fit in 4000 tokens.
212
+
213
+ ## How it works
214
+
215
+ ```
216
+ task text
217
+
218
+ ├─ anchors four independent sources nominate entry points:
219
+ │ explicit names, task history, full-text, vector
220
+ ├─ expansion fixed-shape graph walk: callers 2 hops, callees 1,
221
+ │ references, type hierarchy, same-file siblings
222
+ ├─ scoring weighted sum over reference kind, task signal, centrality,
223
+ │ distance, leaf penalty, edge provenance
224
+ ├─ scope drop repositories this caller may not see
225
+ ├─ narrowing keep the top N
226
+ ├─ assembly fit the token budget, cheaper detail further out
227
+ └─ coverage report how much of this is trustworthy
228
+ ```
229
+
230
+ Callers reach two hops and callees only one, on purpose: when you change a function, what
231
+ breaks is upstream of it. Reference kind carries the heaviest weight, because a place that
232
+ *writes* a value is where the bug lives while a place that *reads* it is usually just
233
+ downstream. Centrality saturates at degree 20, because a logger touches everything and
234
+ explains nothing.
235
+
236
+ The full formula, every weight, and the confidence thresholds are in
237
+ [docs/retrieval.md](docs/retrieval.md).
238
+
239
+ ## Features
240
+
241
+ - **Code graph, not chunks.** Symbols, `CALLS`, `REFERENCES`, `INHERITS`, `IMPLEMENTS`,
242
+ `IMPORTS`, HTTP `ROUTES_TO` handlers, and `WHY:` comments bound to what they explain.
243
+ - **Deterministic by construction.** Sorted traversal, stable tiebreaks, versioned scoring
244
+ weights. `bce bench` verifies it by running each case repeatedly and comparing output.
245
+ - **Six languages.** Python, JavaScript and TypeScript built in; Java, C# and Go behind the
246
+ `langs` extra. [Adding one](docs/languages.md#adding-a-language) touches two files.
247
+ - **Cross-language call edges.** React Native and Expo bridges connect
248
+ `NativeModules.Foo.bar()` in TypeScript to `bar` in Objective-C, Swift or Kotlin — a hole
249
+ no single parser can see.
250
+ - **Edge provenance you can audit.** `scip` from a real compiler index, `treesitter` from
251
+ syntax, `heuristic` from a pattern match. Scored differently, reported per response.
252
+ - **Incremental re-indexing.** `git diff` decides what to re-parse. Symbol ids survive file
253
+ moves and reformatting, so history and embeddings stay valid.
254
+ - **One database.** Apache AGE and pgvector in the same PostgreSQL, so one query joins a
255
+ graph traversal, a vector search and a SQL filter — and one `pg_dump` backs up the index.
256
+ - **MCP and REST from one implementation.** Fourteen tools over stdio, the same functions
257
+ over HTTP. Nothing to drift.
258
+ - **A UI that explains itself.** `/ui` ships in the wheel and replays a real retrieval call
259
+ stage by stage: anchors lighting up, expansion spreading, candidates scored and cut.
260
+ - **Runs offline.** The default embedding provider is deterministic arithmetic over token
261
+ digests. No API key, no network, repeatable benchmarks.
262
+
263
+ ## Where it fits
264
+
265
+ | | Embedding RAG | Language server | BGTS Context Engine |
266
+ | --- | --- | --- | --- |
267
+ | Retrieval basis | text similarity | compiler index | code graph + anchors |
268
+ | Cross-file, cross-repo | weak | per project | yes |
269
+ | Cross-language edges | no | no | yes, heuristic |
270
+ | Same query, same answer | no | yes | yes |
271
+ | Ranked for *a task* | by similarity | not ranked | yes, with coverage |
272
+ | Token budget aware | chunk count | no | yes, detail by distance |
273
+ | Explains its own answer | no | no | anchors + provenance + confidence |
274
+
275
+ A language server is exact but scoped to what you have open. Embedding search is broad but
276
+ unaccountable. This sits between them: repository-wide and cross-language like the former,
277
+ exact and reproducible like the latter.
278
+
279
+ ## Measuring it
280
+
281
+ Retrieval quality claims are worthless without the task set they were measured on, so the
282
+ harness ships instead of a leaderboard. You give it your own tasks and the symbols you
283
+ believe answer them:
284
+
285
+ ```bash
286
+ bce bench --cases my-tasks.json --out report.json
287
+ ```
288
+
289
+ Each case is a task text plus its ground-truth `symbol_id`s. The report gives recall,
290
+ precision, precision@1 and MRR per case, median and p95 latency, and two pass/fail checks
291
+ that matter more than the scores: every case is run repeatedly and must return a
292
+ byte-identical ordering, and any case with a scoped principal must not surface a repository
293
+ that principal cannot read.
294
+
295
+ Building the case file is the real work — it means deciding, by hand, what the right answer
296
+ is. It is also the only honest way to know whether a change to the scoring weights helped.
297
+ The format and a worked example are in
298
+ [docs/deployment.md](docs/deployment.md#benchmarking).
299
+
300
+ ## Roadmap
301
+
302
+ Ordered by how often it comes up, not by difficulty:
303
+
304
+ - **Scope enforcement on every layer.** Layer 3 applies the per-user repository filter;
305
+ Layers 1 and 2 do not. Until that closes, the API belongs behind a proxy — see
306
+ [SECURITY.md](SECURITY.md).
307
+ - **Streamable HTTP transport for MCP.** Today the MCP surface is stdio only, so the server
308
+ runs next to the agent. Remote transport makes one index serve a team.
309
+ - **More languages.** Rust, Kotlin and PHP are the most requested. The provider interface is
310
+ the contribution path with the least friction — see
311
+ [docs/languages.md](docs/languages.md#adding-a-language).
312
+ - **Wider SCIP ingestion.** Compiler-grade edges beat syntax-derived ones and are scored as
313
+ such; more toolchains means more of the graph carries `scip` provenance.
314
+ - **A published benchmark corpus.** An open task set over public repositories, so results
315
+ are comparable between projects rather than only between your own runs.
316
+
317
+ Requests and disagreements belong in
318
+ [issues](https://github.com/bgts-ai/bgts-context-engine/issues) — what people
319
+ actually ask for reorders this list.
320
+
321
+ ## Documentation
322
+
323
+ | | |
324
+ | --- | --- |
325
+ | [Architecture](docs/architecture.md) | the deterministic line, the three layers, indexing |
326
+ | [Retrieval](docs/retrieval.md) | anchors, expansion, every scoring weight, confidence |
327
+ | [Data model](docs/data-model.md) | node labels, edge types, tables, symbol identity |
328
+ | [MCP and API](docs/mcp.md) | all 14 tools, every endpoint, the CLI |
329
+ | [Languages](docs/languages.md) | what each parser extracts, and how to add one |
330
+ | [Deployment](docs/deployment.md) | configuration reference, jobs, backup, benchmarking |
331
+ | [Web interface](web/README.md) | developing the frontend |
332
+
333
+ ## Contributing
334
+
335
+ Contributions are welcome — especially new languages, which is the contribution the
336
+ pipeline is most ready for.
337
+
338
+ Read [CONTRIBUTING.md](CONTRIBUTING.md) first. The one rule worth knowing up front:
339
+ **determinism is the product.** A change that makes the same task return different results
340
+ will not be merged without an explicit opt-in flag, and anything touching scoring or
341
+ ordering needs a test that pins the output.
342
+
343
+ ```bash
344
+ pip install -e ".[dev,mcp]"
345
+ ruff check src tests scripts && pytest
346
+ cd web && npm ci && npm test
347
+ ```
348
+
349
+ ## Security
350
+
351
+ The engine has no authentication of its own and expects to sit behind something that does.
352
+ Only the Layer-3 endpoints apply the per-user repository scope. Read
353
+ [SECURITY.md](SECURITY.md) before exposing a port, and report vulnerabilities privately
354
+ rather than in an issue.
355
+
356
+ ## License
357
+
358
+ [MIT](LICENSE) © BilgeAdam Technology.
359
+
360
+ Built by [Oğuz Öztürk](https://github.com/oztrkoguz) and
361
+ [Enes İyidil](https://github.com/enesiyidil).