Repository navigation
Expand file tree
/
Copy pathpyproject.toml
More file actions
393 lines (368 loc) · 16 KB
/
Copy pathpyproject.toml
File metadata and controls
393 lines (368 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
[project]
name = "code-graph-rag"
version = "0.7.210"
description = "The ultimate RAG for your monorepo. Query, understand, and edit multi-language codebases with the power of AI and knowledge graphs"
readme = "PYPI_README.md"
requires-python = ">=3.12"
license = "MIT"
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
# cgr requires cgr-graph-rs, whose CPython wheels cover these systems only.
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
keywords = [
"rag",
"retrieval-augmented-generation",
"knowledge-graph",
"code-analysis",
"tree-sitter",
"mcp",
"mcp-server",
"llm",
"graph-database",
"semantic-search",
"codebase",
"memgraph",
"developer-tools",
"monorepo",
]
dependencies = [
"loguru>=0.7.3",
# codebase_rag/mcp/server.py registers its handlers through the 2.x
# Server constructor, which 1.x lacks, and every documented install
# resolves this range rather than uv.lock (#2519).
"mcp>=2.3.0,<3",
# mcp's server extracts W3C trace context from every request's `_meta`,
# and before 1.45.2 a traceparent there parses in quadratic time
# (GHSA-mf5v-w3w3-f6cg). Declared so an upgrade over an older install
# moves it too, as mcp and pydantic-ai-slim still accept the old one.
"opentelemetry-api>=1.45.2",
# The MCP server checks tool arguments against their input schemas, which
# the 1.x SDK did for it.
"jsonschema>=4.20.0",
# Only the providers codebase_rag/providers imports. The `pydantic-ai`
# meta-package also installs logfire, evals, a CLI and a web UI, none used.
"pydantic-ai-slim[anthropic,google,openai]>=2.0.0",
"pydantic-settings>=2.12.0",
"python-dotenv>=1.2.1",
"tiktoken>=0.12.0",
"tree-sitter-python>=0.25.0",
"tree-sitter==0.27.0",
"watchdog>=6.0.0",
"typer>=0.21.1",
"rich>=14.2.0",
"prompt-toolkit>=3.0.52",
"diff-match-patch>=20241021",
"click>=8.3.3",
"protobuf>=6.33.5",
# codebase_rag/stack/manager.py reads docker-compose files with it, and
# the CLI imports that module on every run.
"pyyaml>=6.0",
"pathspec>=1.0.4",
"pygments>=2.20.0",
# Imported directly (embedder, health checks, token counting, web
# search). It used to arrive only through the provider SDKs, and
# google-genai 3 moved to httpx2, which a fresh install then took alone.
"httpx>=0.28.1",
# certifi is the CA bundle httpx and requests verify against; 2026.10.23
# is the first without the distrusted eMudhra roots. Declared so an
# upgrade over an older install moves it too.
"certifi>=2026.10.23",
# The embedded graph's `=~`: unlike `re`, a match takes a timeout, so a
# backtracking pattern stops at the query's deadline. tiktoken already
# installs it.
"regex>=2024.11.6",
# The Rust half that does the work behind the Python interface
# (rust/cgr_graph_rs), required everywhere: cgr does not run without it.
# It ships as abi3 wheels for CPython on Linux x86_64/aarch64, macOS and
# Windows x64, and has no sdist, so other platforms cannot install cgr.
# The floor is the crate version this code was written against, raised
# with each crate release.
"cgr-graph-rs>=0.1.32,<0.2",
]
[project.scripts]
code-graph-rag = "codebase_rag.cli:app"
cgr = "codebase_rag.cli:app"
[project.entry-points.pytest11]
cgr_trace = "codebase_rag.trace.pytest_plugin"
[tool.uv]
package = true
# Patched grammars: upstream tree-sitter-c drops declarations after a
# #define whose value embeds a block comment (issue #555). Our forks carry
# the repeat(preproc_arg) fix. cgr-graph-rs compiles them in at these commits
# and cgr parses C and C++ with that copy on every install, since PyPI
# refuses dependencies from git; these overrides give a checkout the forks'
# Python packages, which test_grammar_pins.py compares the compiled grammars
# with. Drop both once upstream releases the fix.
[tool.uv.sources]
# A checkout builds the crate it carries (with a Rust toolchain), so the
# Python and Rust halves of a change are tested together; installs from
# PyPI get the published wheels.
cgr-graph-rs = { path = "rust/cgr_graph_rs" }
tree-sitter-c = { git = "https://github.com/vitali87/tree-sitter-c", rev = "fa327ad98f847f8173fc46926be4165c7971f960" }
tree-sitter-cpp = { git = "https://github.com/vitali87/tree-sitter-cpp", rev = "b4a7be2f62f36dd460a14b2d1728d42d81d2c486" }
[tool.setuptools.packages.find]
include = ["codebase_rag*", "codec*", "cgr*"]
exclude = ["*.tests", "*.tests.*"]
[tool.setuptools.package-data]
codebase_rag = [
"docker-compose.yaml",
"parsers/csharp_frontend/roslyn/*.cs",
"parsers/csharp_frontend/roslyn/*.csproj",
"parsers/go_frontend/gotypes/*.go",
"parsers/go_frontend/gotypes/go.mod",
"parsers/go_frontend/gotypes/go.sum",
"parsers/java_frontend/javac/cgr/*.java",
"parsers/ast_grep_patterns/*.yaml",
"analyzers/ast_grep_rules/*/*.yaml",
# Julia's pip grammar ships no HIGHLIGHTS_QUERY, so its highlights come
# only from this fallback file; without it the wheel silently disables
# Julia modifier/decorator extraction (issue #1882 review).
"queries/highlights/*.scm",
# The tracer agents the dynamic-tracing guide builds or loads; `cgr trace
# agent <language>` prints where an installed copy keeps each (issue #2684).
"trace/c_agent/*.c",
"trace/lua_agent/*.lua",
"trace/dart_collector/pubspec.yaml",
"trace/dart_collector/pubspec.lock",
"trace/dart_collector/bin/*.dart",
"trace/jvm_agent/MANIFEST.MF",
"trace/jvm_agent/src/cgr/trace/*.java",
]
# The provenance manifest hashes this file to stamp each index with its codec
# schema; without it every installed build writes a null hash and
# `cgr diff-index` refuses its indexes (issue #2399).
codec = ["schema.proto"]
[project.optional-dependencies]
test = [
"jedi>=0.19",
"pytest>=8.4.1",
"pytest-asyncio>=1.0.0",
"pytest-cov>=4.0.0",
"pytest-xdist>=3.8.0",
"testcontainers>=4.9.0",
"libclang>=18.1.1",
"filelock>=3.12",
"ast-grep-py>=0.51.3",
"pyyaml>=6.0",
# The suite exercises the Memgraph backend with a mocked server, but
# imports the real driver's exception types to do it.
"pymgclient>=1.6.0",
# The `sqlite` vector store's tests run against a real sqlite-vec file.
"sqlite-vec>=0.1.9",
]
cpp = [
"libclang>=18.1.1",
]
# Memgraph is an optional backend since the embedded graph became the
# default (issue #386). Its driver is a C extension that builds with cmake
# wherever no wheel fits, the setup step first-time users tripped on.
# TransientError, which the ingestor retries, first appears in 1.6.0.
memgraph = [
"pymgclient>=1.6.0",
]
# Neo4j is an optional backend (issue #1590), so a default install must not
# pay for a driver it will never load.
neo4j = [
"neo4j>=5.28.1",
]
treesitter-full = [
"tree-sitter-python>=0.23.6",
"tree-sitter-javascript>=0.23.1",
"tree-sitter-typescript>=0.23.2",
"tree-sitter-rust>=0.24.0",
# Exact pins, as cgr-graph-rs compiles each of these three grammars in
# (rust/cgr_graph_rs/Cargo.toml): Go's at this release, and C's and C++'s
# as the forks above, whose versions these are. Each moves with its crate
# pin in one pull request (AGENTS.md); test_grammar_pins.py fails while
# the two disagree. C and C++ load from the crate, never from these.
"tree-sitter-go==0.25.0",
"tree-sitter-scala>=0.24.0",
"tree-sitter-java>=0.23.5",
"tree-sitter-c==0.24.1",
"tree-sitter-cpp==0.23.4",
"tree-sitter-lua>=0.0.19",
"tree-sitter-julia>=0.23.1",
"tree-sitter-php>=0.24.1",
"tree-sitter-c-sharp>=0.23.5",
# Exact pin: PyPI's tree-sitter-dart is a single-maintainer repackaging of
# a fork, so a new release is a new publisher decision, not a grammar fix.
"tree-sitter-dart==0.1.0",
"tree-sitter-sql>=0.3.11",
"tree-sitter-markdown>=0.5.1",
]
# sqlite-vec is the default vector store's, on the platforms it ships wheels
# for (it has no sdist), which cover every one torch ships wheels for; no
# marker tells musl from glibc, and torch has no musl wheels either.
# qdrant-client is for CGR_VECTOR_STORE_BACKEND=qdrant, the default before it.
semantic = [
"qdrant-client>=1.9.0",
# The gRPC client verifies TLS against grpcio's own roots.pem; 1.84.1 is
# the first without emSign ECC Root CA - G3.
"grpcio>=1.84.1",
"sqlite-vec>=0.1.9; (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or sys_platform == 'darwin' or (sys_platform == 'win32' and platform_machine == 'AMD64')",
"torch>=2.6.0",
"transformers>=5.0.0",
# transformers downloads the UniXcoder model through it, and nothing
# outside this extra imports it, so a default install leaves it out with
# the five packages it brings (hf-xet, fsspec, tqdm, filelock, packaging).
"huggingface-hub[hf-xet]>=1.7.2",
]
milvus = [
"pymilvus[milvus-lite]>=3.0.0",
# As in `semantic`: pymilvus's gRPC client trusts grpcio's roots.pem.
"grpcio>=1.84.1",
]
# The default `sqlite` vector store alone, for an install that computes its
# embeddings elsewhere (CGR_EMBEDDING_PROVIDER=openai): vectors in a file
# beside the embedded graph, so semantic search needs no server either.
sqlite-vec = [
"sqlite-vec>=0.1.9",
]
ast-grep = [
"ast-grep-py>=0.51.3",
"pyyaml>=6.0",
]
python-semantics = [
"jedi>=0.19",
]
[tool.ruff]
line-length = 88
target-version = "py312"
exclude = ["codec/", "benchmarks/", "optimize/"]
[tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "PL", "T201", "S"]
ignore = [
"E501", # line too long
"PLR2004", # magic value comparison (too noisy)
"PLC0415", # import not at top-level (intentional lazy imports)
"PLR0913", # too many arguments (often unavoidable)
"PLR0917", # too many positional arguments (often unavoidable)
"PLR0911", # too many return statements
"PLR0912", # too many branches
"PLR0915", # too many statements
"PLW2901", # loop variable overwritten (intentional for .strip())
"PLW0603", # global statement (singleton pattern)
"S101", # assert (Bandit skips B101 too)
"S105", # password-by-name heuristic: fires on *_TOKEN / PASS_* constants; secret scanning covers real secrets
"S106", # same heuristic for keyword arguments
"S107", # same heuristic for argument defaults
"S603", # any subprocess call with an argv list; the shell=True rules (S602, S604, S605) stay on
"S607", # toolchains resolve from PATH by design; shutil.which reads the same PATH
]
[tool.ruff.lint.per-file-ignores]
# Tests are outside Bandit's and SonarCloud's security scope too.
"**/tests/**" = ["T201", "S"]
"benchmarks/**" = ["T201"]
"evals/flows_corpus/**" = ["T201"]
# The corpus builder is a CLI script; its output is the point.
"fuzz/build_corpus.py" = ["T201"]
# The embedded graph engine compiles Cypher to SQL, so composing SQL text is
# its job. Identifiers in that text are generated by the compiler and string
# literals pass through `sql_str`; every value supplied with a query reaches
# SQLite as a bound parameter, never spliced into the statement.
"codebase_rag/embedded_graph/**" = ["S608"]
[tool.ruff.format]
quote-style = "double"
[tool.ty.environment]
python-version = "3.12"
[tool.ty.src]
exclude = ["codebase_rag/tests/test_cypher_queries.py", "codebase_rag/tests/test_code_retrieval.py", "codebase_rag/tests/test_call_resolver.py", "benchmarks/", "optimize/"]
[tool.coverage.run]
# `codebase_rag/constants/` is excluded because coverage cannot say anything
# useful about it, not because it is untested (issue #1599).
#
# Those 31 modules are almost entirely module-level assignments. A constant
# definition executes exactly once, at import, and cannot fail to execute if
# the module is imported at all -- so the measurement is 100% or 0% depending
# on whether tracing had started by then, never on whether anything is tested.
# Measured under pytest it is 0/2858 lines, because conftest imports
# `graph_updater` (which alone pulls all 31) during collection, before
# pytest-cov begins tracing. Importing the same package after starting
# coverage manually records the lines normally.
#
# Keeping it in the denominator understated source coverage by ~2856 lines and
# made `constants/` read as the largest gap in the tree while carrying no
# signal in either direction. Excluding it makes the remaining figure mean
# something; it does not hide dead code, since an unused constant executes at
# import exactly like a used one and coverage could never have flagged it.
#
# This is not a new judgement: `sonar-project.properties` already carries
# `sonar.coverage.exclusions=...,codebase_rag/constants/**`. The two tools
# disagreed, and this makes Codecov match the call the project had made.
omit = ["codebase_rag/constants/*"]
[tool.pytest.ini_options]
asyncio_mode = "auto"
# loadgroup honors the xdist_group marker that pins the integration dir to
# one worker; for unmarked tests it schedules identically to the default.
# xdist workers decide their grouping flag from the parsed args/ini before
# any conftest hook fires (xdist remote.py setup_config), so this must be
# an ini-level option; every dependency set that carries pytest also
# carries pytest-xdist, so the flag always parses. The shard plugin
# registers `--shard`, which CI uses to split the suite across jobs
# (codebase_rag/tests/suite_shards.py says why it is not a conftest hook),
# and the engine-modes plugin `--engine-mode`, which picks the engine the
# suite indexes on (docs/reports/PHASE1_SEAMS.md, section 2).
addopts = "--dist=loadgroup -p codebase_rag.tests.suite_shards -p codebase_rag.tests.engine_modes"
# A test still running after this many seconds, its fixtures included, has
# every thread's stack written to stderr, and goes on: a hang the job's
# 45-minute cap would cancel without a word names itself first (issue #3740:
# every Windows worker sat at 30% for 30 minutes). The slowest test that is
# not hung, test_engine_change_detection.py's shadow driver, takes 12 to 18
# minutes on Windows, about half its shard, so it can pass 20 only in a run
# the cap cancels anyway. Nested pytest sessions read it too.
faulthandler_timeout = 1200
testpaths = ["codebase_rag/tests"]
norecursedirs = ["grammars", ".git", "__pycache__", "*.egg-info", ".venv", "venv"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"slow: marks tests as slow (may download models or require external services)",
"integration: marks tests as integration tests requiring Docker",
"e2e: marks tests as end-to-end tests",
"index_engine(spec): runs the test, and any cgr it starts, with CGR_INDEX_ENGINE=spec, whatever --engine-mode sets",
]
[dependency-groups]
dev = [
"bandit>=1.9.2",
"coverage>=7.13.0",
"pre-commit>=4.2.0",
"pyinstaller>=6.14.1",
"pytest>=9.0.2",
"pytest-xdist>=3.8.0",
# ty resolves the Memgraph driver's types where the code names them.
"pymgclient>=1.6.0",
"ruff>=0.5.5",
"ty>=0.0.7",
"types-protobuf>=5.0.0",
]
docs = [
# Exact pin while Zensical is pre-1.0.
"zensical==0.1.1",
]
fuzz = [
"atheris>=2.3.0",
]
# Builds the cgr-graph-rs wheels (.github/workflows/rust-wheels.yml): zig
# links each Linux wheel against the oldest glibc or musl its tag promises.
rust-wheels = [
"maturin==1.16.0",
# Only the Linux wheels are linked with zig, and it ships no Windows build.
"ziglang==0.17.1; sys_platform == 'linux'",
]
[tool.bandit]
exclude_dirs = ["codebase_rag/tests", "scripts", "benchmarks", "optimize"]
skips = ["B101"]