repo2graph 1.4.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.

Potentially problematic release.


This version of repo2graph might be problematic. Click here for more details.

Files changed (32) hide show
  1. repo2graph-1.4.0/LICENSE +21 -0
  2. repo2graph-1.4.0/PKG-INFO +364 -0
  3. repo2graph-1.4.0/README.md +328 -0
  4. repo2graph-1.4.0/pyproject.toml +73 -0
  5. repo2graph-1.4.0/repo2graph/__init__.py +19 -0
  6. repo2graph-1.4.0/repo2graph/answer.py +309 -0
  7. repo2graph-1.4.0/repo2graph/chunks.py +211 -0
  8. repo2graph-1.4.0/repo2graph/cli.py +490 -0
  9. repo2graph-1.4.0/repo2graph/embed.py +273 -0
  10. repo2graph-1.4.0/repo2graph/export.py +639 -0
  11. repo2graph-1.4.0/repo2graph/fetch.py +218 -0
  12. repo2graph-1.4.0/repo2graph/graph.py +437 -0
  13. repo2graph-1.4.0/repo2graph/langs.py +9 -0
  14. repo2graph-1.4.0/repo2graph/layout.py +31 -0
  15. repo2graph-1.4.0/repo2graph/mcp.py +438 -0
  16. repo2graph-1.4.0/repo2graph/parse.py +520 -0
  17. repo2graph-1.4.0/repo2graph/query.py +710 -0
  18. repo2graph-1.4.0/repo2graph/viz.py +654 -0
  19. repo2graph-1.4.0/repo2graph/walker.py +27 -0
  20. repo2graph-1.4.0/repo2graph.egg-info/PKG-INFO +364 -0
  21. repo2graph-1.4.0/repo2graph.egg-info/SOURCES.txt +30 -0
  22. repo2graph-1.4.0/repo2graph.egg-info/dependency_links.txt +1 -0
  23. repo2graph-1.4.0/repo2graph.egg-info/entry_points.txt +3 -0
  24. repo2graph-1.4.0/repo2graph.egg-info/requires.txt +13 -0
  25. repo2graph-1.4.0/repo2graph.egg-info/top_level.txt +1 -0
  26. repo2graph-1.4.0/setup.cfg +4 -0
  27. repo2graph-1.4.0/tests/test_budget.py +137 -0
  28. repo2graph-1.4.0/tests/test_compat.py +564 -0
  29. repo2graph-1.4.0/tests/test_mcp.py +1005 -0
  30. repo2graph-1.4.0/tests/test_rag.py +1479 -0
  31. repo2graph-1.4.0/tests/test_repo2graph.py +2074 -0
  32. repo2graph-1.4.0/tests/test_vectors.py +675 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Srinivasan-78
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,364 @@
1
+ Metadata-Version: 2.4
2
+ Name: repo2graph
3
+ Version: 1.4.0
4
+ Summary: Turn any repository into a code graph + graph-aware RAG chunks
5
+ Author-email: Srinivasan Vijayaraghavan <srinivasan.shyam2000@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Srinivasan-78/repo2graph
8
+ Project-URL: Repository, https://github.com/Srinivasan-78/repo2graph
9
+ Project-URL: Issues, https://github.com/Srinivasan-78/repo2graph/issues
10
+ Project-URL: MCP server, https://github.com/Srinivasan-78/repo2graph/blob/main/docs/mcp.md
11
+ Keywords: mcp,model-context-protocol,code-graph,graphrag,rag,tree-sitter,static-analysis,codebase-search
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Documentation
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Text Processing :: Indexing
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: tree-sitter>=0.23
26
+ Requires-Dist: tree-sitter-language-pack>=0.7
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7; extra == "dev"
29
+ Requires-Dist: ruff>=0.5; extra == "dev"
30
+ Provides-Extra: rag
31
+ Requires-Dist: sentence-transformers>=3.0; extra == "rag"
32
+ Requires-Dist: numpy>=1.24; extra == "rag"
33
+ Provides-Extra: mcp
34
+ Requires-Dist: mcp<2,>=1.0; extra == "mcp"
35
+ Dynamic: license-file
36
+
37
+ <!--
38
+ @authormark v1 -- do not remove (authorship watermark)⁠​‌‌‌​​​​​‌‌‌​‌​‌​‌‌‌​​​‌​‌​‌​​​​​​‌‌​​​​​​‌‌​​‌​​‌​​‌​​‌​‌​‌​‌​‌​‌‌‌​‌‌​​‌‌​​‌​‌​‌‌‌​‌​​​‌‌‌​​​‌​‌‌‌​‌‌‌​‌‌​​​‌‌​​‌‌​‌​‌​‌​​‌‌‌​​‌‌‌​​‌‌​‌​​​​‌‌​​‌‌​‌‌​​‌‌​​​​‌​‌‌‌‌​​​​​‌‌‌​​‌⁠
39
+ Copyright (c) 2026 Srinivasan Vijayaraghavan <srinivasan.shyam2000@gmail.com>
40
+ Author: https://github.com/Srinivasan-78
41
+ SPDX-License-Identifier: MIT
42
+ Fingerprint: AMK1.puqP02IUvetqwc5NsC6ax9
43
+ -->
44
+ # repo2graph
45
+
46
+ <!-- mcp-name: io.github.Srinivasan-78/repo2graph -->
47
+
48
+ repo2graph reads a folder full of code and draws you a map of it — then uses that map to answer
49
+ questions about the code, with citations. Agents can ask it questions directly over MCP.
50
+
51
+ ![The whole map of a project: 300 dots and the arrows between them](docs/images/graph-overview.png)
52
+
53
+ *One project, drawn by `repo2graph`. Each dot is a folder, file, function or library. Each arrow is
54
+ a real connection found in the code.*
55
+
56
+ ## The idea
57
+
58
+ Imagine you get handed a big box of Lego that someone else already built things with. You want to
59
+ know what connects to what. You could look at every brick one at a time, or someone could hand you
60
+ a map.
61
+
62
+ Code is like that box. A project has hundreds of files, and the files use each other in ways you
63
+ cannot see by looking at one file at a time.
64
+
65
+ repo2graph makes the map. On the map:
66
+
67
+ - Every **thing** is a dot. A folder is a dot. A file is a dot. A function (a small named piece of
68
+ code that does a job) is a dot. We call these dots **nodes**.
69
+ - Every **connection** is an arrow. "This file is inside that folder." "This function uses that
70
+ function." "This file borrows code from that library." We call these arrows **edges**.
71
+
72
+ Dots joined by arrows are called a **graph**. That is the whole idea.
73
+
74
+ ## Why a map helps
75
+
76
+ If you search a project for the word "login", you get every file that happens to say "login",
77
+ including comments and typos.
78
+
79
+ The map is better, because it knows which function actually does the login work, and it also knows
80
+ which functions call it and which functions it calls. So you get the real answer plus its
81
+ neighbours.
82
+
83
+ That matters most when a chatbot or AI helper is reading the code for you. Giving it the right
84
+ piece of code plus the pieces around it is usually what it was missing.
85
+
86
+ ## How it works, in three steps
87
+
88
+ ```mermaid
89
+ flowchart LR
90
+ A[your code] --> B[tree-sitter<br/>reads the code]
91
+ B --> C[graph<br/>dots + arrows]
92
+ C --> D[graph.html<br/>the picture]
93
+ C --> E[overview.md<br/>the words]
94
+ C --> F[chunks.jsonl<br/>pieces for an AI]
95
+ C --> G[graph.graphml / graph.cypher<br/>other tools, Neo4j]
96
+ ```
97
+
98
+ 1. **It reads the code.** It uses tree-sitter, the same tool code editors use to colour your code.
99
+ So it understands real code structure instead of guessing from words. It needs no setup and
100
+ works on a project it has never seen.
101
+ 2. **It builds the map.** Folders, files, functions, classes and imports become dots. "contains",
102
+ "defines", "calls", "imports", "inherits" become arrows.
103
+ 3. **It cuts the code into small pieces.** Roughly one piece per function or class. Each piece gets
104
+ a few lines at the top saying who calls this function, what it calls, and what its description
105
+ says. Those little pieces are what you feed to an AI when you want it to answer questions about
106
+ the code.
107
+
108
+ No graph library is involved: degree counting, layout and GraphML generation are pure Python, with
109
+ no NetworkX.
110
+
111
+ ## Install
112
+
113
+ You need Python 3.10 or newer.
114
+
115
+ ```bash
116
+ pip install repo2graph
117
+ ```
118
+
119
+ Two optional extras, neither needed for the core:
120
+
121
+ ```bash
122
+ pip install "repo2graph[rag]" # sentence-transformers + numpy, for meaning-based search
123
+ pip install "repo2graph[mcp]" # the MCP SDK, for serving the map to an agent
124
+ ```
125
+
126
+ To run it without installing anything — which is how most people wire up the MCP server — use
127
+ [uv](https://docs.astral.sh/uv/):
128
+
129
+ ```bash
130
+ uvx repo2graph build . -o .r2g
131
+ uvx --from "repo2graph[mcp]" repo2graph-mcp /path/to/project
132
+ ```
133
+
134
+ Or from a checkout, if you want to change it:
135
+
136
+ ```bash
137
+ git clone https://github.com/Srinivasan-78/repo2graph
138
+ cd repo2graph
139
+ python3 -m venv .venv
140
+ .venv/bin/pip install -e ".[dev]"
141
+ ```
142
+
143
+ ## Use it
144
+
145
+ ### 1. Make the map
146
+
147
+ ```bash
148
+ repo2graph build /path/to/your/project -o .r2g --git-history 200
149
+ ```
150
+
151
+ That is it. It walks the project, reads it, and puts everything in a folder called `.r2g`. A medium
152
+ project takes seconds. A very big one takes a minute or two.
153
+
154
+ `--git-history 200` is optional. It looks at the last 200 saves (commits) in the project's history
155
+ and adds links between files that keep getting changed together. Those links are a good clue about
156
+ which files secretly depend on each other.
157
+
158
+ No copy on your machine? Point it at GitHub instead — it downloads, maps, and tidies up after
159
+ itself:
160
+
161
+ ```bash
162
+ repo2graph github psf/requests -o out/requests --git-history 200
163
+ ```
164
+
165
+ ### 2. Look at the map
166
+
167
+ ```bash
168
+ open .r2g/human/graph.html # the picture
169
+ cat .r2g/human/overview.md # the same thing written out in words
170
+ repo2graph stats -o .r2g # how many dots, arrows and functions there are
171
+ ```
172
+
173
+ `graph.html` is one single file. No internet needed, nothing to install. Open it in a browser and
174
+ you get the picture: drag to move around, scroll to zoom, drag a dot to pin it in place, click a
175
+ dot to see what that function looks like and everything it is connected to.
176
+
177
+ Zoom in and every dot is named, so you can read the real call paths:
178
+
179
+ ![Zoomed into the map: named functions, files and libraries joined by arrows](docs/images/graph-zoom.png)
180
+
181
+ The side panel counts what is on screen and lets you switch each kind of dot and arrow on or off:
182
+
183
+ ![Side panel with search box, node kinds and relationship kinds, each with a count](docs/images/graph-sidebar.png)
184
+
185
+ By default the picture shows the 300 busiest dots, and hides calls that go out to other people's
186
+ code, because those triple the number of arrows and tell you little about your own project. Tick
187
+ `external` and `CALLS_EXTERNAL` in the side panel to show them. Want a simpler picture? Redraw it
188
+ with fewer dots: `repo2graph map -o .r2g --viz-nodes 80`.
189
+
190
+ ### 3. Ask it questions
191
+
192
+ A search tool and a GraphRAG context packer are built in. Neither needs an AI account.
193
+
194
+ ```bash
195
+ repo2graph query "how does routing match a path" -o .r2g # find the code
196
+ repo2graph rag "how does the pack stay inside its budget" -o .r2g # pack it for an LLM
197
+ ```
198
+
199
+ `query` finds the best matching pieces and follows the arrows one step out, so the functions around
200
+ each answer come along too. `rag` does the same and then assembles a budget-bounded markdown pack,
201
+ repo map on top, every block stamped with an exact citation header:
202
+
203
+ ```
204
+ ### [cite: repo2graph/cli.py:22-28] `parse_formats` (CALLS out of cmd_build)
205
+ # file: repo2graph/cli.py
206
+ # function: parse_formats (lines 22-28, python)
207
+ # called by: repo2graph/cli.py::cmd_build, repo2graph/cli.py::cmd_github
208
+ def parse_formats(spec: str) -> set[str]:
209
+ ...
210
+ ```
211
+
212
+ The `(CALLS out of cmd_build)` part is the *reason* the block is in the pack: either `seed` (the
213
+ search found it) or the arrow that dragged it in.
214
+
215
+ Word matching misses code that says the same thing in different words, so you can add meaning-based
216
+ search on top — vectors are computed once, then blended into every ranking:
217
+
218
+ ```bash
219
+ repo2graph embed -o .r2g # needs the [rag] extra
220
+ repo2graph rag "how is a request routed" -o .r2g --vectors
221
+ ```
222
+
223
+ `repo2graph rag --answer` will also send the pack to an LLM and stream back a grounded answer. It is
224
+ the one command that puts your source code on the network — read
225
+ [the warning](docs/cli.md#-answer-sends-your-code-to-someone-elses-computer) first.
226
+
227
+ **Full flag tables, budget accounting and how retrieval works: [docs/cli.md](docs/cli.md).**
228
+
229
+ ### 4. Hand the map to an agent over MCP
230
+
231
+ `repo2graph-mcp` is a stdio [MCP](https://modelcontextprotocol.io) server, so an agent can ask the
232
+ map questions itself instead of you pasting a pack into a chat window.
233
+
234
+ Point it at a project and it serves it. Nothing to install and no setup step: if no map exists yet,
235
+ the first question builds one and answers from it.
236
+
237
+ ```bash
238
+ claude mcp add repo2graph -- uvx --from "repo2graph[mcp]" repo2graph-mcp /path/to/project
239
+ ```
240
+
241
+ For Claude Desktop, Cursor and generic clients, the JSON block is the same four lines:
242
+
243
+ ```json
244
+ {
245
+ "mcpServers": {
246
+ "repo2graph": {
247
+ "command": "uvx",
248
+ "args": ["--from", "repo2graph[mcp]", "repo2graph-mcp", "/path/to/project"]
249
+ }
250
+ }
251
+ }
252
+ ```
253
+
254
+ Three tools, deliberately:
255
+
256
+ | Tool | Arguments | What comes back |
257
+ |---|---|---|
258
+ | `repo_map` | none | Languages, hub files and top entry points. Stable across calls, so it caches. |
259
+ | `repo_search` | `query`, optional `k`, `hops`, `budget_tokens` | Seed chunks plus their graph neighbours, each headed `[cite: path:start-end]`. |
260
+ | `repo_neighbours` | `node_id`, optional `hops`, `limit` | One graph hop from a symbol: callers, callees, base classes, defining file. The thing grep cannot do. |
261
+
262
+ The server keeps three promises the CLI leaves to you: secrets are **always** excluded, output is
263
+ hard-capped at 12 000 tokens and re-measured before it is returned, and `k`/`hops` are clamped so no
264
+ single call can wedge the event loop every client shares. It never calls an LLM itself.
265
+
266
+ Auto-build writes only what the tools read, and only into a directory you pointed it at. Build ahead
267
+ with `repo2graph build` if you want the first question to be fast or want the picture too, and pass
268
+ `--no-auto-build` to require an index that already exists.
269
+
270
+ **Client configs, which directory gets indexed, and the full contract: [docs/mcp.md](docs/mcp.md).**
271
+
272
+ ### 5. Or run it in CI
273
+
274
+ repo2graph is on the GitHub Marketplace, so a fresh map can live next to your code:
275
+
276
+ ```yaml
277
+ - uses: actions/checkout@v4
278
+ with: { fetch-depth: 0 } # full history, so CO_CHANGE edges are meaningful
279
+ - uses: Srinivasan-78/repo2graph@v1
280
+ with:
281
+ path: .
282
+ git-history: "500"
283
+ artifact-name: repo-graph
284
+ ```
285
+
286
+ **All inputs and outputs: [docs/github-action.md](docs/github-action.md).**
287
+
288
+ ## What you get in `.r2g`
289
+
290
+ The output is split in two, because people and programs want different things.
291
+
292
+ ```
293
+ .r2g/
294
+ ├── human/ overview.md graph.html graph.graphml
295
+ └── agent/ overview.md manifest.json chunks.jsonl
296
+ nodes.jsonl edges.jsonl graph.cypher stats.json
297
+ ```
298
+
299
+ `agent/manifest.json` is the instruction sheet: what every other file is, what the dots and arrows
300
+ mean, how names are built, and where the code starts. A program needs nothing else to make sense of
301
+ the folder.
302
+
303
+ `chunks.jsonl` is the file you hand to an AI system. Each piece already carries its neighbours in
304
+ the header, which is what makes the answers good. If you use a vector database, keep each piece's
305
+ `node_id` — that is the handle that lets you jump back onto the map after a search.
306
+
307
+ **Every file, every node and edge kind, the chunk format: [docs/reference.md](docs/reference.md).**
308
+
309
+ ## Using it from Python
310
+
311
+ ```python
312
+ from pathlib import Path
313
+ from repo2graph import build, iter_chunks
314
+ from repo2graph.export import dump_all
315
+ from repo2graph.query import Index
316
+
317
+ g = build(Path("."), git_history=200)
318
+ dump_all(g, chunks=iter_chunks(g), outdir=Path(".r2g"),
319
+ formats={"jsonl", "overview", "html"}, viz_nodes=300)
320
+
321
+ pack = Index(".r2g").pack_context("how does session auth work?", k=8, hops=1,
322
+ budget_chars=24000)
323
+ print(pack["markdown"])
324
+ ```
325
+
326
+ `Index` is the same object the CLI, the Action and the MCP server all call.
327
+
328
+ **Streaming exports, expanding your own vector hits, loading into Neo4j:
329
+ [docs/python-api.md](docs/python-api.md).**
330
+
331
+ ## Languages
332
+
333
+ Python, JavaScript, TypeScript and TSX, Go, Rust, Java, Ruby, C, C++, C#, PHP, Kotlin, Swift, Scala
334
+ and Bash get the full treatment: functions, classes and calls. Files in any other language still
335
+ appear on the map as files in their folders, so nothing goes missing. Teaching it a new language
336
+ means adding one entry to `LANG_CFG` in `repo2graph/langs.py`.
337
+
338
+ ## Where it guesses
339
+
340
+ The map is very good, but it is not perfect. Worth knowing before you trust it:
341
+
342
+ - **It matches calls by name, not by type.** If two functions share a name, repo2graph draws up to
343
+ 5 possible arrows and marks each one `1/n` sure. If you need certainty, keep only the arrows where
344
+ `confidence` is `1.0`.
345
+ - **Some files are skipped:** pictures and other non-text files, anything bigger than 1.5 MB, and
346
+ the usual vendor and build folders. In a git checkout, `.gitignore` is respected.
347
+ - **No arrow does not prove no call.** Code that decides while running which function to call is
348
+ invisible to a reader like this one.
349
+
350
+ [The rest, including how imports are resolved per language](docs/reference.md#where-it-guesses).
351
+
352
+ ## Contributing
353
+
354
+ ```bash
355
+ .venv/bin/pip install -e ".[dev]"
356
+ .venv/bin/python -m pytest
357
+ ```
358
+
359
+ See [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md). Source files carry an `@authormark`
360
+ watermark header — read [AGENTS.md](AGENTS.md) before editing one.
361
+
362
+ ## Licence
363
+
364
+ MIT. See [LICENSE](LICENSE).