pycode-kg 0.16.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 (62) hide show
  1. pycode_kg-0.16.0/LICENSE +94 -0
  2. pycode_kg-0.16.0/PKG-INFO +305 -0
  3. pycode_kg-0.16.0/README.md +231 -0
  4. pycode_kg-0.16.0/pyproject.toml +229 -0
  5. pycode_kg-0.16.0/src/pycode_kg/.DS_Store +0 -0
  6. pycode_kg-0.16.0/src/pycode_kg/__init__.py +91 -0
  7. pycode_kg-0.16.0/src/pycode_kg/__main__.py +11 -0
  8. pycode_kg-0.16.0/src/pycode_kg/analysis/__init__.py +15 -0
  9. pycode_kg-0.16.0/src/pycode_kg/analysis/bridge.py +108 -0
  10. pycode_kg-0.16.0/src/pycode_kg/analysis/centrality.py +412 -0
  11. pycode_kg-0.16.0/src/pycode_kg/analysis/framework_detector.py +103 -0
  12. pycode_kg-0.16.0/src/pycode_kg/analysis/hybrid_rank.py +53 -0
  13. pycode_kg-0.16.0/src/pycode_kg/app.py +1335 -0
  14. pycode_kg-0.16.0/src/pycode_kg/architecture.py +624 -0
  15. pycode_kg-0.16.0/src/pycode_kg/build_pycodekg_lancedb.py +15 -0
  16. pycode_kg-0.16.0/src/pycode_kg/build_pycodekg_sqlite.py +15 -0
  17. pycode_kg-0.16.0/src/pycode_kg/cli/__init__.py +29 -0
  18. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_analyze.py +96 -0
  19. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_architecture.py +150 -0
  20. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_bridges.py +26 -0
  21. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_build.py +154 -0
  22. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_build_full.py +242 -0
  23. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_centrality.py +131 -0
  24. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_explain.py +180 -0
  25. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_framework_nodes.py +18 -0
  26. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_hooks.py +137 -0
  27. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_init.py +312 -0
  28. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_mcp.py +71 -0
  29. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_model.py +53 -0
  30. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_query.py +211 -0
  31. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_snapshot.py +421 -0
  32. pycode_kg-0.16.0/src/pycode_kg/cli/cmd_viz.py +180 -0
  33. pycode_kg-0.16.0/src/pycode_kg/cli/main.py +23 -0
  34. pycode_kg-0.16.0/src/pycode_kg/cli/options.py +63 -0
  35. pycode_kg-0.16.0/src/pycode_kg/config.py +78 -0
  36. pycode_kg-0.16.0/src/pycode_kg/graph.py +125 -0
  37. pycode_kg-0.16.0/src/pycode_kg/index.py +542 -0
  38. pycode_kg-0.16.0/src/pycode_kg/kg.py +220 -0
  39. pycode_kg-0.16.0/src/pycode_kg/layout3d.py +470 -0
  40. pycode_kg-0.16.0/src/pycode_kg/mcp/bridge_tools.py +19 -0
  41. pycode_kg-0.16.0/src/pycode_kg/mcp/framework_tools.py +18 -0
  42. pycode_kg-0.16.0/src/pycode_kg/mcp_server.py +1965 -0
  43. pycode_kg-0.16.0/src/pycode_kg/module/__init__.py +83 -0
  44. pycode_kg-0.16.0/src/pycode_kg/module/base.py +720 -0
  45. pycode_kg-0.16.0/src/pycode_kg/module/extractor.py +276 -0
  46. pycode_kg-0.16.0/src/pycode_kg/module/types.py +532 -0
  47. pycode_kg-0.16.0/src/pycode_kg/pycodekg.py +543 -0
  48. pycode_kg-0.16.0/src/pycode_kg/pycodekg_query.py +1 -0
  49. pycode_kg-0.16.0/src/pycode_kg/pycodekg_snippet_packer.py +1 -0
  50. pycode_kg-0.16.0/src/pycode_kg/pycodekg_thorough_analysis.py +2751 -0
  51. pycode_kg-0.16.0/src/pycode_kg/pycodekg_viz.py +1 -0
  52. pycode_kg-0.16.0/src/pycode_kg/pycodekg_viz3d.py +1 -0
  53. pycode_kg-0.16.0/src/pycode_kg/ranking/__init__.py +1 -0
  54. pycode_kg-0.16.0/src/pycode_kg/ranking/cli_rank.py +92 -0
  55. pycode_kg-0.16.0/src/pycode_kg/ranking/coderank.py +555 -0
  56. pycode_kg-0.16.0/src/pycode_kg/snapshots.py +612 -0
  57. pycode_kg-0.16.0/src/pycode_kg/sql/004_add_centrality_table.sql +12 -0
  58. pycode_kg-0.16.0/src/pycode_kg/store.py +766 -0
  59. pycode_kg-0.16.0/src/pycode_kg/utils.py +39 -0
  60. pycode_kg-0.16.0/src/pycode_kg/visitor.py +413 -0
  61. pycode_kg-0.16.0/src/pycode_kg/viz3d.py +1353 -0
  62. pycode_kg-0.16.0/src/pycode_kg/viz3d_timeline.py +364 -0
@@ -0,0 +1,94 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ **You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.**
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor's trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to the
37
+ software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms or the URL for them above, as well as copies of
47
+ any plain-text lines beginning with "Required Notice:" that the licensor provided
48
+ with the software. For example:
49
+
50
+ Required Notice: Copyright (c) 2026 Eric G. Suchanek, PhD
51
+
52
+ ## No Other Rights
53
+
54
+ These terms do not imply any other licenses not expressly granted in this
55
+ license.
56
+
57
+ ## Termination
58
+
59
+ If you use the software in violation of these terms, such use is not licensed,
60
+ and your licenses will automatically terminate. If the licensor provides you with
61
+ a notice of your violation, and you cease all violation of this license no later
62
+ than 30 days after you receive that notice, your licenses will be reinstated
63
+ retroactively. However, if you violate these terms after such reinstatement, any
64
+ additional violation of these terms will cause your licenses to terminate
65
+ automatically and permanently.
66
+
67
+ ## No Liability
68
+
69
+ *As far as the law allows, the software comes as is, without any warranty or
70
+ condition, and the licensor will not be liable to you for any damages arising out
71
+ of these terms or the use or nature of the software, under any kind of legal
72
+ claim.*
73
+
74
+ ## Definitions
75
+
76
+ The **licensor** is the entity offering these terms, and the **software** is the
77
+ software the licensor makes available under these terms, including any portion of
78
+ it.
79
+
80
+ **You** refers to the individual or entity agreeing to these terms.
81
+
82
+ **Your company** is any legal entity, sole proprietorship, or other kind of
83
+ organization that you work for, plus all organizations that have control over,
84
+ are under the control of, or are under common control with that organization.
85
+ Control means ownership of substantially all the assets of an entity, or the
86
+ power to direct its management and policies by vote, contract, or otherwise.
87
+ Control can be direct or indirect.
88
+
89
+ **Your licenses** are all the licenses granted to you for the software under
90
+ these terms.
91
+
92
+ **Use** means anything you do with the software requiring one of your licenses.
93
+
94
+ **Trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1,305 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycode-kg
3
+ Version: 0.16.0
4
+ Summary: A tool to build a searchable knowledge graph from Python repositories
5
+ License-Expression: Elastic-2.0
6
+ License-File: LICENSE
7
+ Keywords: knowledge-graph,code-analysis,ast,lancedb,sqlite,semantic-search
8
+ Author: Eric G. Suchanek, PhD
9
+ Author-email: suchanek@mac.com
10
+ Requires-Python: >=3.12,<3.14
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Provides-Extra: all
19
+ Provides-Extra: dev
20
+ Provides-Extra: kgdeps
21
+ Provides-Extra: viz
22
+ Provides-Extra: viz3d
23
+ Requires-Dist: PyQt5 (>=5.15.0) ; extra == "all"
24
+ Requires-Dist: PyQt5 (>=5.15.0) ; extra == "viz3d"
25
+ Requires-Dist: click (>=8.1.0,<9)
26
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "all"
27
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "dev"
28
+ Requires-Dist: doc-kg (>=0.11.0) ; extra == "dev"
29
+ Requires-Dist: doc-kg (>=0.11.0) ; extra == "kgdeps"
30
+ Requires-Dist: kg-snapshot (>=0.3.0)
31
+ Requires-Dist: lancedb (>=0.29.0)
32
+ Requires-Dist: markdown (>=3.6) ; extra == "all"
33
+ Requires-Dist: markdown (>=3.6) ; extra == "viz3d"
34
+ Requires-Dist: mcp (>=1.0.0)
35
+ Requires-Dist: mypy (>=1.10.0) ; extra == "all"
36
+ Requires-Dist: mypy (>=1.10.0) ; extra == "dev"
37
+ Requires-Dist: numpy (>=1.24.0)
38
+ Requires-Dist: pandas (>=2.0.0)
39
+ Requires-Dist: param (>=2.0.0) ; extra == "all"
40
+ Requires-Dist: param (>=2.0.0) ; extra == "viz3d"
41
+ Requires-Dist: pdoc (>=14.0.0) ; extra == "all"
42
+ Requires-Dist: pdoc (>=14.0.0) ; extra == "dev"
43
+ Requires-Dist: plotly (>=5.14.0) ; extra == "all"
44
+ Requires-Dist: plotly (>=5.14.0) ; extra == "viz"
45
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "all"
46
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "dev"
47
+ Requires-Dist: pylint (>=4.0.5) ; extra == "all"
48
+ Requires-Dist: pylint (>=4.0.5) ; extra == "dev"
49
+ Requires-Dist: pytest (>=8.0.0) ; extra == "all"
50
+ Requires-Dist: pytest (>=8.0.0) ; extra == "dev"
51
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "all"
52
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "dev"
53
+ Requires-Dist: pyvis (>=0.3.2) ; extra == "all"
54
+ Requires-Dist: pyvis (>=0.3.2) ; extra == "viz"
55
+ Requires-Dist: pyvista[jupyter] (>=0.44.0) ; extra == "all"
56
+ Requires-Dist: pyvista[jupyter] (>=0.44.0) ; extra == "viz3d"
57
+ Requires-Dist: pyvistaqt (>=0.11.0) ; extra == "all"
58
+ Requires-Dist: pyvistaqt (>=0.11.0) ; extra == "viz3d"
59
+ Requires-Dist: rich (>=14.3.3,<15)
60
+ Requires-Dist: ruff (>=0.4.0) ; extra == "all"
61
+ Requires-Dist: ruff (>=0.4.0) ; extra == "dev"
62
+ Requires-Dist: safetensors (>=0.5.0)
63
+ Requires-Dist: sentence-transformers (>=5.4.1)
64
+ Requires-Dist: streamlit (>=1.35.0) ; extra == "all"
65
+ Requires-Dist: streamlit (>=1.35.0) ; extra == "viz"
66
+ Requires-Dist: torch (>=2.5.1)
67
+ Requires-Dist: trame-vtk (>=2.0.0) ; extra == "all"
68
+ Requires-Dist: trame-vtk (>=2.0.0) ; extra == "viz3d"
69
+ Requires-Dist: transformers (>=4.57.6)
70
+ Project-URL: Homepage, https://github.com/Flux-Frontiers/pycode_kg
71
+ Project-URL: Repository, https://github.com/Flux-Frontiers/pycode_kg
72
+ Description-Content-Type: text/markdown
73
+
74
+
75
+ [![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue.svg)](https://www.python.org/)
76
+ [![License: Elastic-2.0](https://img.shields.io/badge/License-Elastic%202.0-blue.svg)](https://www.elastic.co/licensing/elastic-license)
77
+ [![Version](https://img.shields.io/badge/version-0.16.0-blue.svg)](https://github.com/Flux-Frontiers/pycode_kg/releases)
78
+ [![CI](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml)
79
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
80
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
81
+
82
+ <p align="center">
83
+ <img src="assets/logo-md-256x256.png" alt="PyCodeKG logo" width="256"/>
84
+ </p>
85
+
86
+ **PyCodeKG** — A Deterministic Knowledge Graph for Python Codebases
87
+ with Semantic Indexing and Source-Grounded Snippet Packing
88
+
89
+ *Author: Eric G. Suchanek, PhD*
90
+
91
+ *Flux-Frontiers, Liberty TWP, OH*
92
+
93
+ [Technical Paper (PDF)](article/pycode_kg.pdf)
94
+
95
+ ---
96
+
97
+ ## Overview
98
+
99
+ PyCodeKG constructs a **deterministic, explainable knowledge graph** from a Python codebase using static analysis. The graph captures structural relationships — definitions, calls, imports, and inheritance — directly from the Python AST, stores them in SQLite, and augments retrieval with vector embeddings via LanceDB.
100
+
101
+ Structure is treated as **ground truth**; semantic search is strictly an acceleration layer. The result is a searchable, auditable representation of a codebase that supports precise navigation, contextual snippet extraction, and downstream reasoning without hallucination.
102
+
103
+ ---
104
+
105
+ ## What Agents Say
106
+
107
+ *From independent assessments run against PyCodeKG's own codebase. See [assessments/](assessments/) for the full reports.*
108
+
109
+ > "The workflow compression is real and substantial. Rather than reading files sequentially or running grep searches in the dark, an agent equipped with PyCodeKG can orient itself in seconds."
110
+ > — Claude Sonnet 4.6
111
+
112
+ > "Replaces hours of manual exploration with a single call. The most valuable tool in the suite."
113
+ > — Claude Opus 4, on `analyze_repo()`
114
+
115
+ > "It let me move from broad orientation to intent-driven discovery and then to structural validation without dropping down into manual grep or repeated file reads."
116
+ > — GPT-5 (via Cline)
117
+
118
+ > "Traditional file reading and grep-based exploration are slow, linear, and context-poor. PyCodeKG's semantic search, graph navigation, and architectural analysis provide a quantum leap in speed and depth of understanding."
119
+ > — GPT-4.1
120
+
121
+ > "`pack_snippets()` provided source excerpts around each hit, making the code instantly readable. Context lines and relevance metadata obviated manual file open."
122
+ > — Raptor Mini
123
+
124
+ > "Dramatically more effective than traditional grep/file-reading workflows. Unique value proposition: hybrid search combining natural-language intent with precise structural relationships."
125
+ > — Claude Haiku 4.5
126
+
127
+ ---
128
+
129
+ ## Quick Start
130
+
131
+ Run the one-line installer from within the repo you want to index:
132
+
133
+ ```bash
134
+ curl -fsSL https://raw.githubusercontent.com/Flux-Frontiers/pycode_kg/main/scripts/install-skill.sh | bash
135
+ ```
136
+
137
+ This sets up everything end-to-end:
138
+
139
+ 1. Installs SKILL.md reference files for Claude Code, Kilo Code, and other agents
140
+ 2. Installs Claude Code slash commands (`/pycodekg`, `/setup-mcp`)
141
+ 3. Installs the `pycode-kg` package if not already present
142
+ 4. Builds the SQLite knowledge graph and LanceDB semantic index
143
+ 5. Writes MCP configuration for Claude Code, Kilo Code, GitHub Copilot, and Cline
144
+
145
+ After the script completes, restart your AI agent to activate the MCP server.
146
+
147
+ ```bash
148
+ # Preview without making changes
149
+ curl -fsSL .../install-skill.sh | bash -s -- --dry-run
150
+
151
+ # Claude Code and GitHub Copilot only
152
+ curl -fsSL .../install-skill.sh | bash -s -- --providers claude,copilot
153
+ ```
154
+
155
+ → **Full installation options, manual setup, and MCP config:** [docs/INSTALLATION.md](docs/INSTALLATION.md)
156
+
157
+ ---
158
+
159
+ ## Features
160
+
161
+ - **Static analysis pipeline** — Three-pass AST extraction: structure, call graph, data-flow
162
+ - **Deterministic knowledge graph** — SQLite-backed canonical store with provenance
163
+ - **Symbol resolution** — `RESOLVES_TO` edges bridge cross-module call sites via import aliases
164
+ - **Hybrid query model** — Semantic seeding (LanceDB) + structural expansion (graph traversal)
165
+ - **Source-grounded snippet packing** — Definition and call-site snippets with line numbers
166
+ - **Precise fan-in lookup** — Two-phase reverse traversal resolving cross-module caller chains
167
+ - **MCP server** — Ten tools for AI agent integration
168
+ - **Streamlit web app** — Interactive graph browser, hybrid query UI, snippet pack explorer
169
+ - **3D visualizer** — PyVista/PyQt5 interactive graph explorer
170
+ - **Zero-config MCP setup** — Single-line installer configures Claude Code, Kilo Code, GitHub Copilot, and Cline
171
+
172
+ ---
173
+
174
+ ## Usage
175
+
176
+ ```bash
177
+ # Build the knowledge graph
178
+ pycodekg build --repo /path/to/your/repo
179
+
180
+ # Natural-language query
181
+ pycodekg query "authentication flow"
182
+
183
+ # Source-grounded snippet pack — paste straight into an LLM prompt
184
+ pycodekg pack "database connection setup" --format md --out context.md
185
+
186
+ # Full architectural analysis
187
+ pycodekg analyze /path/to/your/repo
188
+
189
+ # Launch the interactive web app
190
+ pycodekg viz
191
+
192
+ # Start the MCP server
193
+ pycodekg mcp --repo /path/to/your/repo
194
+ ```
195
+
196
+ ### MCP Tools (once the server is running)
197
+
198
+ ```
199
+ graph_stats() # node/edge counts by kind
200
+ query_codebase("authentication flow") # hybrid semantic + structural search
201
+ pack_snippets("database layer") # source-grounded snippets as Markdown
202
+ get_node("fn:store:GraphStore.write") # fetch a single node by ID
203
+ callers("fn:store:GraphStore.write") # precise fan-in lookup
204
+ explain("fn:store:GraphStore.write") # natural-language explanation
205
+ analyze_repo() # full architectural analysis as Markdown
206
+ snapshot_list() # list saved snapshots with deltas
207
+ snapshot_show("latest") # inspect the latest snapshot
208
+ snapshot_diff("<key_a>", "<key_b>") # compare two snapshots
209
+ ```
210
+
211
+ ### Python API
212
+
213
+ ```python
214
+ from pycode_kg import PyCodeKG
215
+
216
+ kg = PyCodeKG(repo_root="/path/to/repo")
217
+ kg.build(wipe=True)
218
+
219
+ result = kg.query("database connection setup", k=8, hop=1)
220
+ for node in result.nodes:
221
+ print(node["id"], node["name"])
222
+
223
+ pack = kg.pack("authentication flow")
224
+ pack.save("context.md")
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Architecture
230
+
231
+ <p align="center">
232
+ <img src="assets/codeKG_arch_square-web.jpg" alt="PyCodeKG architecture workflow" width="600"/>
233
+ </p>
234
+
235
+ ```
236
+ Repository
237
+
238
+ AST parsing — Pass 1: structure, Pass 2: calls, Pass 3: data-flow
239
+
240
+ SQLite graph — nodes + edges
241
+
242
+ Symbol resolution — RESOLVES_TO edges (sym: stubs → fn:/cls: defs)
243
+
244
+ Vector indexing — LanceDB
245
+
246
+ Hybrid query — semantic + graph
247
+
248
+ Ranking + deduplication
249
+
250
+ ├──▶ Streamlit web app
251
+ └──▶ MCP server tools
252
+ ```
253
+
254
+ The five design principles:
255
+
256
+ 1. **Structure is authoritative** — The AST-derived graph is the source of truth.
257
+ 2. **Semantics accelerate, never decide** — Embeddings seed and rank retrieval but never invent structure.
258
+ 3. **Everything is traceable** — Nodes and edges map to concrete files and line numbers.
259
+ 4. **Determinism over heuristics** — Identical input yields identical output.
260
+ 5. **Composable artifacts** — SQLite for structure, LanceDB for vectors, Markdown/JSON for consumption.
261
+
262
+ → **Full architecture documentation:** [docs/Architecture.md](docs/Architecture.md)
263
+
264
+ ---
265
+
266
+ ## Contribution Checklist
267
+
268
+ When changing MCP tools in `src/pycode_kg/mcp_server.py` (signature, params, defaults, or behavior), update all three in the same commit:
269
+
270
+ - Module docstring `Tools` list at the top of `src/pycode_kg/mcp_server.py`
271
+ - `mcp = FastMCP(..., instructions=(...))` tool descriptions in `src/pycode_kg/mcp_server.py`
272
+ - The runtime tool implementation and `:param:` docstrings
273
+
274
+ ---
275
+
276
+ ## Citation
277
+
278
+ If you use PyCodeKG in your research or project, please cite it:
279
+
280
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
281
+
282
+ **APA**
283
+
284
+ > Suchanek, E. G. (2026). *PyCodeKG: Semantic Knowledge Graph for Python Codebases* (Version 0.15.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.PLACEHOLDER
285
+
286
+ **BibTeX**
287
+
288
+ ```bibtex
289
+ @software{suchanek_pycode_kg,
290
+ author = {Suchanek, Eric G.},
291
+ title = {{PyCodeKG}: Semantic Knowledge Graph for Python Codebases},
292
+ version = {0.15.0},
293
+ year = {2026},
294
+ publisher = {Flux-Frontiers},
295
+ url = {https://github.com/Flux-Frontiers/pycode_kg},
296
+ doi = {10.5281/zenodo.PLACEHOLDER},
297
+ }
298
+ ```
299
+
300
+ ---
301
+
302
+ ## License
303
+
304
+ [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license) — see [LICENSE](LICENSE).
305
+
@@ -0,0 +1,231 @@
1
+
2
+ [![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue.svg)](https://www.python.org/)
3
+ [![License: Elastic-2.0](https://img.shields.io/badge/License-Elastic%202.0-blue.svg)](https://www.elastic.co/licensing/elastic-license)
4
+ [![Version](https://img.shields.io/badge/version-0.16.0-blue.svg)](https://github.com/Flux-Frontiers/pycode_kg/releases)
5
+ [![CI](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/pycode_kg/actions/workflows/ci.yml)
6
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
7
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
8
+
9
+ <p align="center">
10
+ <img src="assets/logo-md-256x256.png" alt="PyCodeKG logo" width="256"/>
11
+ </p>
12
+
13
+ **PyCodeKG** — A Deterministic Knowledge Graph for Python Codebases
14
+ with Semantic Indexing and Source-Grounded Snippet Packing
15
+
16
+ *Author: Eric G. Suchanek, PhD*
17
+
18
+ *Flux-Frontiers, Liberty TWP, OH*
19
+
20
+ [Technical Paper (PDF)](article/pycode_kg.pdf)
21
+
22
+ ---
23
+
24
+ ## Overview
25
+
26
+ PyCodeKG constructs a **deterministic, explainable knowledge graph** from a Python codebase using static analysis. The graph captures structural relationships — definitions, calls, imports, and inheritance — directly from the Python AST, stores them in SQLite, and augments retrieval with vector embeddings via LanceDB.
27
+
28
+ Structure is treated as **ground truth**; semantic search is strictly an acceleration layer. The result is a searchable, auditable representation of a codebase that supports precise navigation, contextual snippet extraction, and downstream reasoning without hallucination.
29
+
30
+ ---
31
+
32
+ ## What Agents Say
33
+
34
+ *From independent assessments run against PyCodeKG's own codebase. See [assessments/](assessments/) for the full reports.*
35
+
36
+ > "The workflow compression is real and substantial. Rather than reading files sequentially or running grep searches in the dark, an agent equipped with PyCodeKG can orient itself in seconds."
37
+ > — Claude Sonnet 4.6
38
+
39
+ > "Replaces hours of manual exploration with a single call. The most valuable tool in the suite."
40
+ > — Claude Opus 4, on `analyze_repo()`
41
+
42
+ > "It let me move from broad orientation to intent-driven discovery and then to structural validation without dropping down into manual grep or repeated file reads."
43
+ > — GPT-5 (via Cline)
44
+
45
+ > "Traditional file reading and grep-based exploration are slow, linear, and context-poor. PyCodeKG's semantic search, graph navigation, and architectural analysis provide a quantum leap in speed and depth of understanding."
46
+ > — GPT-4.1
47
+
48
+ > "`pack_snippets()` provided source excerpts around each hit, making the code instantly readable. Context lines and relevance metadata obviated manual file open."
49
+ > — Raptor Mini
50
+
51
+ > "Dramatically more effective than traditional grep/file-reading workflows. Unique value proposition: hybrid search combining natural-language intent with precise structural relationships."
52
+ > — Claude Haiku 4.5
53
+
54
+ ---
55
+
56
+ ## Quick Start
57
+
58
+ Run the one-line installer from within the repo you want to index:
59
+
60
+ ```bash
61
+ curl -fsSL https://raw.githubusercontent.com/Flux-Frontiers/pycode_kg/main/scripts/install-skill.sh | bash
62
+ ```
63
+
64
+ This sets up everything end-to-end:
65
+
66
+ 1. Installs SKILL.md reference files for Claude Code, Kilo Code, and other agents
67
+ 2. Installs Claude Code slash commands (`/pycodekg`, `/setup-mcp`)
68
+ 3. Installs the `pycode-kg` package if not already present
69
+ 4. Builds the SQLite knowledge graph and LanceDB semantic index
70
+ 5. Writes MCP configuration for Claude Code, Kilo Code, GitHub Copilot, and Cline
71
+
72
+ After the script completes, restart your AI agent to activate the MCP server.
73
+
74
+ ```bash
75
+ # Preview without making changes
76
+ curl -fsSL .../install-skill.sh | bash -s -- --dry-run
77
+
78
+ # Claude Code and GitHub Copilot only
79
+ curl -fsSL .../install-skill.sh | bash -s -- --providers claude,copilot
80
+ ```
81
+
82
+ → **Full installation options, manual setup, and MCP config:** [docs/INSTALLATION.md](docs/INSTALLATION.md)
83
+
84
+ ---
85
+
86
+ ## Features
87
+
88
+ - **Static analysis pipeline** — Three-pass AST extraction: structure, call graph, data-flow
89
+ - **Deterministic knowledge graph** — SQLite-backed canonical store with provenance
90
+ - **Symbol resolution** — `RESOLVES_TO` edges bridge cross-module call sites via import aliases
91
+ - **Hybrid query model** — Semantic seeding (LanceDB) + structural expansion (graph traversal)
92
+ - **Source-grounded snippet packing** — Definition and call-site snippets with line numbers
93
+ - **Precise fan-in lookup** — Two-phase reverse traversal resolving cross-module caller chains
94
+ - **MCP server** — Ten tools for AI agent integration
95
+ - **Streamlit web app** — Interactive graph browser, hybrid query UI, snippet pack explorer
96
+ - **3D visualizer** — PyVista/PyQt5 interactive graph explorer
97
+ - **Zero-config MCP setup** — Single-line installer configures Claude Code, Kilo Code, GitHub Copilot, and Cline
98
+
99
+ ---
100
+
101
+ ## Usage
102
+
103
+ ```bash
104
+ # Build the knowledge graph
105
+ pycodekg build --repo /path/to/your/repo
106
+
107
+ # Natural-language query
108
+ pycodekg query "authentication flow"
109
+
110
+ # Source-grounded snippet pack — paste straight into an LLM prompt
111
+ pycodekg pack "database connection setup" --format md --out context.md
112
+
113
+ # Full architectural analysis
114
+ pycodekg analyze /path/to/your/repo
115
+
116
+ # Launch the interactive web app
117
+ pycodekg viz
118
+
119
+ # Start the MCP server
120
+ pycodekg mcp --repo /path/to/your/repo
121
+ ```
122
+
123
+ ### MCP Tools (once the server is running)
124
+
125
+ ```
126
+ graph_stats() # node/edge counts by kind
127
+ query_codebase("authentication flow") # hybrid semantic + structural search
128
+ pack_snippets("database layer") # source-grounded snippets as Markdown
129
+ get_node("fn:store:GraphStore.write") # fetch a single node by ID
130
+ callers("fn:store:GraphStore.write") # precise fan-in lookup
131
+ explain("fn:store:GraphStore.write") # natural-language explanation
132
+ analyze_repo() # full architectural analysis as Markdown
133
+ snapshot_list() # list saved snapshots with deltas
134
+ snapshot_show("latest") # inspect the latest snapshot
135
+ snapshot_diff("<key_a>", "<key_b>") # compare two snapshots
136
+ ```
137
+
138
+ ### Python API
139
+
140
+ ```python
141
+ from pycode_kg import PyCodeKG
142
+
143
+ kg = PyCodeKG(repo_root="/path/to/repo")
144
+ kg.build(wipe=True)
145
+
146
+ result = kg.query("database connection setup", k=8, hop=1)
147
+ for node in result.nodes:
148
+ print(node["id"], node["name"])
149
+
150
+ pack = kg.pack("authentication flow")
151
+ pack.save("context.md")
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Architecture
157
+
158
+ <p align="center">
159
+ <img src="assets/codeKG_arch_square-web.jpg" alt="PyCodeKG architecture workflow" width="600"/>
160
+ </p>
161
+
162
+ ```
163
+ Repository
164
+
165
+ AST parsing — Pass 1: structure, Pass 2: calls, Pass 3: data-flow
166
+
167
+ SQLite graph — nodes + edges
168
+
169
+ Symbol resolution — RESOLVES_TO edges (sym: stubs → fn:/cls: defs)
170
+
171
+ Vector indexing — LanceDB
172
+
173
+ Hybrid query — semantic + graph
174
+
175
+ Ranking + deduplication
176
+
177
+ ├──▶ Streamlit web app
178
+ └──▶ MCP server tools
179
+ ```
180
+
181
+ The five design principles:
182
+
183
+ 1. **Structure is authoritative** — The AST-derived graph is the source of truth.
184
+ 2. **Semantics accelerate, never decide** — Embeddings seed and rank retrieval but never invent structure.
185
+ 3. **Everything is traceable** — Nodes and edges map to concrete files and line numbers.
186
+ 4. **Determinism over heuristics** — Identical input yields identical output.
187
+ 5. **Composable artifacts** — SQLite for structure, LanceDB for vectors, Markdown/JSON for consumption.
188
+
189
+ → **Full architecture documentation:** [docs/Architecture.md](docs/Architecture.md)
190
+
191
+ ---
192
+
193
+ ## Contribution Checklist
194
+
195
+ When changing MCP tools in `src/pycode_kg/mcp_server.py` (signature, params, defaults, or behavior), update all three in the same commit:
196
+
197
+ - Module docstring `Tools` list at the top of `src/pycode_kg/mcp_server.py`
198
+ - `mcp = FastMCP(..., instructions=(...))` tool descriptions in `src/pycode_kg/mcp_server.py`
199
+ - The runtime tool implementation and `:param:` docstrings
200
+
201
+ ---
202
+
203
+ ## Citation
204
+
205
+ If you use PyCodeKG in your research or project, please cite it:
206
+
207
+ [![DOI](https://zenodo.org/badge/1202379010.svg)](https://zenodo.org/badge/latestdoi/1202379010)
208
+
209
+ **APA**
210
+
211
+ > Suchanek, E. G. (2026). *PyCodeKG: Semantic Knowledge Graph for Python Codebases* (Version 0.15.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.PLACEHOLDER
212
+
213
+ **BibTeX**
214
+
215
+ ```bibtex
216
+ @software{suchanek_pycode_kg,
217
+ author = {Suchanek, Eric G.},
218
+ title = {{PyCodeKG}: Semantic Knowledge Graph for Python Codebases},
219
+ version = {0.15.0},
220
+ year = {2026},
221
+ publisher = {Flux-Frontiers},
222
+ url = {https://github.com/Flux-Frontiers/pycode_kg},
223
+ doi = {10.5281/zenodo.PLACEHOLDER},
224
+ }
225
+ ```
226
+
227
+ ---
228
+
229
+ ## License
230
+
231
+ [Elastic License 2.0](https://www.elastic.co/licensing/elastic-license) — see [LICENSE](LICENSE).