codebrain 0.1.0__tar.gz → 0.3.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 (179) hide show
  1. {codebrain-0.1.0 → codebrain-0.3.0}/LICENSE +1 -1
  2. codebrain-0.3.0/PKG-INFO +429 -0
  3. codebrain-0.3.0/README.md +358 -0
  4. codebrain-0.3.0/codebrain/__init__.py +10 -0
  5. codebrain-0.3.0/codebrain/actions/__init__.py +16 -0
  6. codebrain-0.3.0/codebrain/actions/base.py +139 -0
  7. codebrain-0.3.0/codebrain/actions/refactor.py +365 -0
  8. codebrain-0.3.0/codebrain/actions/reviewer.py +313 -0
  9. codebrain-0.3.0/codebrain/actions/test_gen.py +283 -0
  10. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/analyzer.py +953 -943
  11. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/api.py +330 -0
  12. codebrain-0.3.0/codebrain/architecture.py +824 -0
  13. codebrain-0.3.0/codebrain/cli.py +4282 -0
  14. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/comprehension.py +98 -31
  15. codebrain-0.3.0/codebrain/config.py +67 -0
  16. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/context.py +1 -0
  17. codebrain-0.3.0/codebrain/cross_query.py +450 -0
  18. codebrain-0.3.0/codebrain/cross_registry.py +328 -0
  19. codebrain-0.3.0/codebrain/diff_impact.py +400 -0
  20. codebrain-0.3.0/codebrain/env_migration.py +560 -0
  21. codebrain-0.3.0/codebrain/equivalence.py +584 -0
  22. codebrain-0.3.0/codebrain/frontend.py +443 -0
  23. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/graph/query.py +308 -18
  24. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/graph/schema.py +66 -1
  25. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/graph/store.py +81 -3
  26. codebrain-0.3.0/codebrain/hook_runner.py +176 -0
  27. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/hooks.py +2 -2
  28. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/indexer.py +85 -1
  29. codebrain-0.3.0/codebrain/kt.py +401 -0
  30. codebrain-0.3.0/codebrain/kt_video.py +948 -0
  31. codebrain-0.3.0/codebrain/mcp_lifecycle.py +327 -0
  32. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/mcp_server.py +2992 -1635
  33. codebrain-0.3.0/codebrain/migration.py +729 -0
  34. codebrain-0.3.0/codebrain/modernize.py +962 -0
  35. codebrain-0.3.0/codebrain/onboard.py +352 -0
  36. codebrain-0.3.0/codebrain/parser/cobol_parser.py +294 -0
  37. codebrain-0.3.0/codebrain/parser/config_parser.py +657 -0
  38. codebrain-0.3.0/codebrain/parser/csharp_parser.py +797 -0
  39. codebrain-0.3.0/codebrain/parser/dart_parser.py +865 -0
  40. codebrain-0.3.0/codebrain/parser/fortran_parser.py +281 -0
  41. codebrain-0.3.0/codebrain/parser/frontend_parser.py +1047 -0
  42. codebrain-0.3.0/codebrain/parser/go_parser.py +560 -0
  43. codebrain-0.3.0/codebrain/parser/java_parser.py +813 -0
  44. codebrain-0.3.0/codebrain/parser/kotlin_parser.py +823 -0
  45. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/models.py +1 -0
  46. codebrain-0.3.0/codebrain/parser/mumps_parser.py +250 -0
  47. codebrain-0.3.0/codebrain/parser/plsql_parser.py +242 -0
  48. codebrain-0.3.0/codebrain/parser/python_parser.py +1255 -0
  49. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/registry.py +97 -1
  50. codebrain-0.3.0/codebrain/parser/rust_parser.py +709 -0
  51. codebrain-0.3.0/codebrain/parser/schema_parser.py +491 -0
  52. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/typescript_treesitter.py +70 -10
  53. codebrain-0.3.0/codebrain/parser/vue_parser.py +353 -0
  54. codebrain-0.3.0/codebrain/rewriter.py +2527 -0
  55. codebrain-0.3.0/codebrain/schema_migration.py +548 -0
  56. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/settings.py +3 -0
  57. codebrain-0.3.0/codebrain/susa_auth.py +157 -0
  58. codebrain-0.3.0/codebrain/test_gaps.py +325 -0
  59. codebrain-0.3.0/codebrain/test_runner.py +878 -0
  60. codebrain-0.3.0/codebrain/tour.py +475 -0
  61. codebrain-0.3.0/codebrain/ui_migration.py +394 -0
  62. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/utils.py +27 -7
  63. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/watcher/file_watcher.py +23 -13
  64. codebrain-0.3.0/codebrain.egg-info/PKG-INFO +429 -0
  65. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain.egg-info/SOURCES.txt +75 -0
  66. codebrain-0.3.0/codebrain.egg-info/entry_points.txt +2 -0
  67. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain.egg-info/requires.txt +1 -0
  68. {codebrain-0.1.0 → codebrain-0.3.0}/pyproject.toml +34 -7
  69. codebrain-0.3.0/tests/test_actions.py +614 -0
  70. codebrain-0.3.0/tests/test_architecture.py +569 -0
  71. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_cli.py +2 -1
  72. codebrain-0.3.0/tests/test_coverage_gaps.py +517 -0
  73. codebrain-0.3.0/tests/test_cross_repo.py +479 -0
  74. codebrain-0.3.0/tests/test_csharp_parser.py +456 -0
  75. codebrain-0.3.0/tests/test_dart_parser.py +487 -0
  76. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_dead_code_confidence.py +17 -12
  77. codebrain-0.3.0/tests/test_diff_impact.py +122 -0
  78. codebrain-0.3.0/tests/test_env_migration.py +243 -0
  79. codebrain-0.3.0/tests/test_equivalence.py +385 -0
  80. codebrain-0.3.0/tests/test_fingerprints.py +327 -0
  81. codebrain-0.3.0/tests/test_frontend.py +1964 -0
  82. codebrain-0.3.0/tests/test_gate_battle.py +321 -0
  83. codebrain-0.3.0/tests/test_go_parser.py +437 -0
  84. codebrain-0.3.0/tests/test_hooks.py +316 -0
  85. codebrain-0.3.0/tests/test_infra_parser.py +239 -0
  86. codebrain-0.3.0/tests/test_java_parser.py +589 -0
  87. codebrain-0.3.0/tests/test_kotlin_parser.py +426 -0
  88. codebrain-0.3.0/tests/test_kt.py +143 -0
  89. codebrain-0.3.0/tests/test_legacy_parsers.py +463 -0
  90. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_llm.py +4 -2
  91. codebrain-0.3.0/tests/test_mcp_lifecycle.py +319 -0
  92. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_mcp_server.py +623 -615
  93. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_memory.py +470 -462
  94. codebrain-0.3.0/tests/test_migration.py +365 -0
  95. codebrain-0.3.0/tests/test_modernize.py +367 -0
  96. codebrain-0.3.0/tests/test_onboard.py +90 -0
  97. codebrain-0.3.0/tests/test_orm_detection.py +293 -0
  98. codebrain-0.3.0/tests/test_output_quality.py +384 -0
  99. codebrain-0.3.0/tests/test_real_codebase.py +223 -0
  100. codebrain-0.3.0/tests/test_real_features.py +448 -0
  101. codebrain-0.3.0/tests/test_real_frontend.py +434 -0
  102. codebrain-0.3.0/tests/test_real_repos.py +878 -0
  103. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_real_world.py +3 -2
  104. codebrain-0.3.0/tests/test_rewriter.py +1331 -0
  105. codebrain-0.3.0/tests/test_rust_parser.py +595 -0
  106. codebrain-0.3.0/tests/test_schema_migration.py +533 -0
  107. codebrain-0.3.0/tests/test_schema_parser.py +328 -0
  108. codebrain-0.3.0/tests/test_test_runner.py +546 -0
  109. codebrain-0.3.0/tests/test_tour.py +101 -0
  110. codebrain-0.3.0/tests/test_translate.py +524 -0
  111. codebrain-0.3.0/tests/test_ui_migration.py +686 -0
  112. codebrain-0.3.0/tests/test_vscode_extension.py +278 -0
  113. codebrain-0.1.0/PKG-INFO +0 -360
  114. codebrain-0.1.0/README.md +0 -316
  115. codebrain-0.1.0/codebrain/__init__.py +0 -3
  116. codebrain-0.1.0/codebrain/cli.py +0 -1927
  117. codebrain-0.1.0/codebrain/config.py +0 -46
  118. codebrain-0.1.0/codebrain/hook_runner.py +0 -71
  119. codebrain-0.1.0/codebrain/parser/config_parser.py +0 -228
  120. codebrain-0.1.0/codebrain/parser/python_parser.py +0 -658
  121. codebrain-0.1.0/codebrain.egg-info/PKG-INFO +0 -360
  122. codebrain-0.1.0/codebrain.egg-info/entry_points.txt +0 -6
  123. codebrain-0.1.0/tests/test_hooks.py +0 -142
  124. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/__main__.py +0 -0
  125. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/agent_bridge.py +0 -0
  126. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/api_models.py +0 -0
  127. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/export.py +0 -0
  128. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/graph/__init__.py +0 -0
  129. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/llm.py +0 -0
  130. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/logging.py +0 -0
  131. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/memory/__init__.py +0 -0
  132. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/memory/store.py +0 -0
  133. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/__init__.py +0 -0
  134. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/base.py +0 -0
  135. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/parser/typescript_parser.py +0 -0
  136. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/py.typed +0 -0
  137. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/resolver.py +0 -0
  138. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/validator.py +0 -0
  139. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain/watcher/__init__.py +0 -0
  140. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain.egg-info/dependency_links.txt +0 -0
  141. {codebrain-0.1.0 → codebrain-0.3.0}/codebrain.egg-info/top_level.txt +0 -0
  142. {codebrain-0.1.0 → codebrain-0.3.0}/setup.cfg +0 -0
  143. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_agent_bridge.py +0 -0
  144. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_analyzer.py +0 -0
  145. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_api.py +0 -0
  146. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_ci.py +0 -0
  147. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_comprehension.py +0 -0
  148. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_context.py +0 -0
  149. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_contracts_real.py +0 -0
  150. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_dataflow.py +0 -0
  151. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_error_recovery.py +0 -0
  152. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_export.py +0 -0
  153. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_indexer.py +0 -0
  154. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_install.py +0 -0
  155. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_integration.py +0 -0
  156. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_jyotishyamitra.py +0 -0
  157. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_multi_project_cli.py +0 -0
  158. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_narratives.py +0 -0
  159. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_parser.py +0 -0
  160. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_plugin_system.py +0 -0
  161. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_production_hardening.py +0 -0
  162. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_query.py +0 -0
  163. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_resolver.py +0 -0
  164. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_scale.py +0 -0
  165. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_scale_optimizations.py +0 -0
  166. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_scale_real.py +0 -0
  167. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_schema.py +0 -0
  168. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_settings.py +0 -0
  169. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_store.py +0 -0
  170. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_ts_ast_parser.py +0 -0
  171. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_ts_parser_enhanced.py +0 -0
  172. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_typescript_parser.py +0 -0
  173. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_utils.py +0 -0
  174. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_validation_narratives.py +0 -0
  175. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_validator.py +0 -0
  176. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_validator_scenarios.py +0 -0
  177. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_watch_validate.py +0 -0
  178. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_watcher.py +0 -0
  179. {codebrain-0.1.0 → codebrain-0.3.0}/tests/test_zoom.py +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 CodeBrain Contributors
3
+ Copyright (c) 2026 CodeBrain Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,429 @@
1
+ Metadata-Version: 2.4
2
+ Name: codebrain
3
+ Version: 0.3.0
4
+ Summary: Know what breaks before you break it. Structural knowledge graph for codebases — impact analysis, dead code detection, health scores. No LLM required.
5
+ Author: CodeBrain Contributors
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 CodeBrain Contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/monk0062006/CodeBrain
29
+ Project-URL: Repository, https://github.com/monk0062006/CodeBrain
30
+ Project-URL: Issues, https://github.com/monk0062006/CodeBrain/issues
31
+ Keywords: code-analysis,static-analysis,knowledge-graph,impact-analysis,dead-code,codebase-health,mcp,ai-coding,structural-analysis,refactoring
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: Topic :: Software Development :: Quality Assurance
40
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
41
+ Classifier: Topic :: Software Development :: Testing
42
+ Classifier: Environment :: Console
43
+ Classifier: Operating System :: OS Independent
44
+ Classifier: Typing :: Typed
45
+ Requires-Python: >=3.11
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: click>=8.1
49
+ Requires-Dist: watchdog>=3.0
50
+ Requires-Dist: mcp<1.20,>=1.0
51
+ Requires-Dist: jinja2>=3.1
52
+ Requires-Dist: psutil>=5.9
53
+ Provides-Extra: api
54
+ Requires-Dist: fastapi>=0.110; extra == "api"
55
+ Requires-Dist: uvicorn>=0.27; extra == "api"
56
+ Provides-Extra: llm
57
+ Requires-Dist: httpx>=0.27; extra == "llm"
58
+ Provides-Extra: ts
59
+ Requires-Dist: tree-sitter>=0.21; extra == "ts"
60
+ Requires-Dist: tree-sitter-languages>=1.10; extra == "ts"
61
+ Provides-Extra: dev
62
+ Requires-Dist: pytest>=7.0; extra == "dev"
63
+ Requires-Dist: pytest-tmp-files>=0.0.2; extra == "dev"
64
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
65
+ Requires-Dist: mypy>=1.8; extra == "dev"
66
+ Requires-Dist: ruff>=0.3; extra == "dev"
67
+ Requires-Dist: httpx>=0.27; extra == "dev"
68
+ Provides-Extra: all
69
+ Requires-Dist: codebrain[api,llm,ts]; extra == "all"
70
+ Dynamic: license-file
71
+
72
+ # CodeBrain
73
+
74
+ **Know what breaks before you break it.**
75
+
76
+ CodeBrain builds a structural knowledge graph of your codebase — every function, class, import, and call chain — stored locally in SQLite. No cloud. No LLM required. Just deterministic structural analysis.
77
+
78
+ ```bash
79
+ pip install codebrain
80
+ cd your-project
81
+ brain init
82
+ ```
83
+
84
+ You'll immediately see:
85
+
86
+ ```
87
+ Indexing my-project (93 files) ...
88
+ Done in 1.2s — 1861 nodes, 8837 edges
89
+
90
+ === Instant Findings ===
91
+ Health: 60/100 (B)
92
+ Riskiest symbols: Flask (34 files), App (35 files), Scaffold (28 files)
93
+ Dead code: 11 candidates (none high-confidence)
94
+ ```
95
+
96
+ Then explore:
97
+
98
+ ```bash
99
+ brain impact my_function # What breaks if I change this?
100
+ brain callers my_function # Who calls this?
101
+ brain health # Codebase health score (0-100)
102
+ brain hotspots # Riskiest symbols in the codebase
103
+ brain deadcode # Unused functions with confidence levels
104
+ brain zoom # Google Maps-style navigation of your architecture
105
+ ```
106
+
107
+ ## Why CodeBrain?
108
+
109
+ AI coding agents (Claude Code, Cursor, Copilot) generate code faster than you can review it. They apply local fixes without understanding global structure. When an agent removes a function, it doesn't know 3 other files call it.
110
+
111
+ CodeBrain knows. It maintains a persistent knowledge graph of every symbol and relationship in your codebase, and can tell you exactly what would break before any change is made.
112
+
113
+ **No API keys. No cloud. No LLM. Everything runs locally on your machine.**
114
+
115
+ ## Features
116
+
117
+ ### Impact Analysis
118
+
119
+ ```
120
+ $ brain impact getAstroData
121
+ Impact of changing predictions_api.py::getAstroData:
122
+ [1] Ascendant.py::compileAstroDetails (CALLS)
123
+ [1] AsthaKoota.py::getNakAndRasi (CALLS)
124
+ [2] ProfileBuilder.py::buildProfile (CALLS via compileAstroDetails)
125
+ ... 48 dependents across 69 files
126
+ ```
127
+
128
+ ### Health Score
129
+
130
+ ```
131
+ $ brain health
132
+ Codebase Health
133
+ Score: 93/100 (A)
134
+ [##################--]
135
+ Dead code: 517 symbols (4.2%) score 79/100
136
+ Import cycles: 0 score 100/100
137
+ Coupling: 3 hotspot(s) score 94/100
138
+ ```
139
+
140
+ ### Risk Hotspots
141
+
142
+ ```
143
+ $ brain hotspots
144
+ Risk hotspots (top 5):
145
+ Score Type Name Deps Files
146
+ 48.2 function getAstroData 48 69
147
+ 35.1 function compileAstroDetails 35 52
148
+ 28.7 class ProfileBuilder 28 41
149
+ ```
150
+
151
+ ### Dead Code Detection
152
+
153
+ Finds unused symbols with confidence levels:
154
+ - **High** — truly unreferenced, safe to delete
155
+ - **Medium** — file uses dynamic patterns (callbacks, registries)
156
+ - **Low** — might be used via reflection or external entry points
157
+
158
+ ### Implicit Contracts
159
+
160
+ ```
161
+ $ brain contracts
162
+ Implicit contracts (12):
163
+ [co_import ] (100%) 'Colors' and 'Spacing' are imported together in 141/141 files
164
+ [co_import ] (98%) 'Spacing' and 'react-native' are imported together in 138/141 files
165
+ ```
166
+
167
+ ### Module Coupling
168
+
169
+ ```
170
+ $ brain coupling
171
+ Most coupled file pairs:
172
+ 140 logger.py <-> main.py
173
+ 101 ForeignSettlementProfile.py <-> ForeignSettlementProfiling.py
174
+ ```
175
+
176
+ ### Architectural Layers
177
+
178
+ ```
179
+ $ brain layers
180
+ Layer 0 — foundation (deepest dependencies)
181
+ utils/logger.py
182
+ utils/constants.py
183
+ Layer 1 — core
184
+ core/engine.py
185
+ core/models.py
186
+ ```
187
+
188
+ ### Multi-Resolution Zoom
189
+
190
+ Navigate your codebase like Google Maps — zoom from system level to package to file to symbol:
191
+
192
+ ```
193
+ $ brain zoom
194
+ System: 1328 files, 17756 symbols across 5 packages
195
+ Backbone: debug_astrodata.py, debug_dasha_data.py, debug_house_data.py
196
+
197
+ $ brain zoom backend
198
+ Package: backend (978 files, 14794 symbols)
199
+ Top modules: ProfileAPI/main.py (429 symbols), test_subscription_tiers.py (210 symbols)
200
+
201
+ $ brain zoom backend/vedic-profiles/ProfileAPI/main.py
202
+ Module: main.py — 429 symbols, 15853 lines. Isolated (no dependents).
203
+ ```
204
+
205
+ ## AI Agent Integration
206
+
207
+ ### Claude Code (MCP)
208
+
209
+ ```bash
210
+ brain setup # auto-generates CLAUDE.md + MCP config
211
+ ```
212
+
213
+ Or add manually to your MCP config:
214
+
215
+ ```json
216
+ {
217
+ "mcpServers": {
218
+ "codebrain": {
219
+ "command": "python",
220
+ "args": ["-m", "codebrain.mcp_server"],
221
+ "cwd": "/path/to/your/repo"
222
+ }
223
+ }
224
+ }
225
+ ```
226
+
227
+ 22 MCP tools available including:
228
+
229
+ | Tool | Purpose |
230
+ |------|---------|
231
+ | `propose_change` | Validate before writing — the structural safety gate |
232
+ | `impact_analysis` | Trace transitive dependents of any symbol |
233
+ | `ask_codebase` | Natural language questions about the codebase |
234
+ | `validate_change` | Check if a file change would break callers |
235
+ | `risk_hotspots` | Find structurally dangerous symbols |
236
+ | `find_dead_code` | Unused symbols with confidence levels |
237
+ | `codebase_overview` | System-level architecture summary |
238
+
239
+ ### Structural Safety Gate
240
+
241
+ The `propose_change` MCP tool validates changes **before** the AI writes them. When a change would remove a function that other files call, or change a signature that callers depend on, CodeBrain blocks it and tells the agent exactly what would break.
242
+
243
+ ## All CLI Commands
244
+
245
+ | Command | Description |
246
+ |---------|-------------|
247
+ | `brain init` | Index the current repository |
248
+ | `brain status` | Show index statistics |
249
+ | `brain search <query>` | Find symbols by name |
250
+ | `brain impact <name>` | What breaks if this changes? |
251
+ | `brain callers <name>` | Who calls this function? (reverse trace) |
252
+ | `brain trace <name>` | Forward call chain from a symbol |
253
+ | `brain deps <name>` | Dependencies of a symbol or file |
254
+ | `brain deadcode` | Find unused functions/classes |
255
+ | `brain cycles` | Detect import cycles |
256
+ | `brain health` | Codebase health score (0-100) |
257
+ | `brain hotspots` | Riskiest symbols by structural exposure |
258
+ | `brain coupling` | Module coupling analysis |
259
+ | `brain contracts` | Implicit contract detection |
260
+ | `brain layers` | Architectural layer inference |
261
+ | `brain zoom [target]` | Multi-resolution navigation |
262
+ | `brain overview` | System-level codebase overview |
263
+ | `brain module <file>` | Module-level view |
264
+ | `brain context <name>` | LLM-optimized symbol context |
265
+ | `brain validate <file>` | Check if a file change is safe |
266
+ | `brain ci --base main` | CI validation for pull requests |
267
+ | `brain watch` | File watcher daemon (re-index on save) |
268
+ | `brain hook install` | Install pre-commit validation hook |
269
+ | `brain reindex` | Force a full rebuild |
270
+ | `brain doctor` | Diagnostic health check |
271
+ | `brain serve` | Start REST API server |
272
+
273
+ All commands support `--json` for machine-readable output, `--repo <path>` for different repos, `--timeout N` for analysis timeout (default: 120s), and `--verbose` for debug logging.
274
+
275
+ ## Configuration
276
+
277
+ Create `.codebrain.toml` in your repo root (optional):
278
+
279
+ ```toml
280
+ [codebrain]
281
+ skip_dirs = ["__pycache__", ".git", "node_modules", "vendor"]
282
+ extensions = [".py", ".ts", ".tsx", ".js", ".jsx"]
283
+ max_file_size_kb = 1024
284
+ cli_timeout = 120
285
+ ```
286
+
287
+ Or use environment variables:
288
+
289
+ | Variable | Description |
290
+ |----------|-------------|
291
+ | `CODEBRAIN_SKIP_DIRS` | Comma-separated directories to skip |
292
+ | `CODEBRAIN_EXTENSIONS` | Comma-separated file extensions to index |
293
+ | `CODEBRAIN_CLI_TIMEOUT` | Analysis timeout in seconds (default: 120) |
294
+ | `CODEBRAIN_MAX_WORKERS` | Max parallel worker processes |
295
+
296
+ ## Language Support
297
+
298
+ | Language | Parser | Quality |
299
+ |----------|--------|---------|
300
+ | Python | AST (stdlib) | Full — functions, classes, imports, calls, dataflow |
301
+ | TypeScript/JSX | tree-sitter | Full — requires `pip install codebrain[ts]` |
302
+ | JavaScript/JSX | tree-sitter | Full — requires `pip install codebrain[ts]` |
303
+ | Java | tree-sitter | Full — Spring Boot aware (DI, endpoints, JPA) |
304
+ | Go | tree-sitter | Full — interfaces, goroutines, struct methods |
305
+ | Rust | tree-sitter | Full — traits, impls, modules, derive macros |
306
+ | C# | tree-sitter | Full — async/await, LINQ, attributes |
307
+ | Kotlin | tree-sitter | Full — coroutines, extensions, data classes |
308
+ | Dart/Flutter | regex | Good — classes, mixins, extensions |
309
+ | Vue SFC | regex | Good — components, props, events |
310
+
311
+ ### Adding Languages
312
+
313
+ Implement `BaseParser` and register via entry points:
314
+
315
+ ```python
316
+ from codebrain.parser.base import BaseParser
317
+ from codebrain.parser.models import ParsedFile
318
+
319
+ class MyParser(BaseParser):
320
+ def extensions(self) -> frozenset[str]:
321
+ return frozenset({".xyz"})
322
+
323
+ def parse(self, path, repo_root) -> ParsedFile:
324
+ ... # parse and return nodes + edges
325
+ ```
326
+
327
+ ```toml
328
+ # pyproject.toml
329
+ [project.entry-points."codebrain.parsers"]
330
+ rust = "your_package.parser:RustParser"
331
+ ```
332
+
333
+ ## CI Integration
334
+
335
+ ### Pre-commit Hook
336
+
337
+ ```bash
338
+ brain hook install # validates staged files before every commit
339
+ brain hook uninstall # remove the hook
340
+ ```
341
+
342
+ ### GitHub Action
343
+
344
+ ```yaml
345
+ name: CodeBrain Validation
346
+ on: [pull_request]
347
+ jobs:
348
+ validate:
349
+ runs-on: ubuntu-latest
350
+ steps:
351
+ - uses: actions/checkout@v4
352
+ with:
353
+ fetch-depth: 0
354
+ - uses: actions/setup-python@v5
355
+ with:
356
+ python-version: '3.11'
357
+ - run: pip install codebrain
358
+ - run: brain ci --base origin/main --json
359
+ ```
360
+
361
+ ## Optional Extras
362
+
363
+ ```bash
364
+ pip install codebrain[ts] # TypeScript/JavaScript tree-sitter parser
365
+ pip install codebrain[api] # REST API server (FastAPI)
366
+ pip install codebrain[llm] # LLM-enhanced explanations (optional, requires API key)
367
+ pip install codebrain[all] # Everything
368
+ ```
369
+
370
+ **The core tool requires no extras.** Python parsing, impact analysis, health scores, dead code detection, coupling analysis — all work out of the box with just `pip install codebrain`.
371
+
372
+ ## How It Works
373
+
374
+ ```
375
+ Source Files --> Parser (Python AST / tree-sitter) --> Nodes + Edges
376
+ |
377
+ GraphStore (SQLite)
378
+ |
379
+ QueryEngine
380
+ |
381
+ CLI / MCP Server / REST API / VS Code Extension
382
+ ```
383
+
384
+ - **Node** — a code symbol (function, class, method, variable, file)
385
+ - **Edge** — a relationship (CALLS, IMPORTS, CONTAINS, EXTENDS, DATAFLOW)
386
+ - **GraphStore** — persistent SQLite database with WAL mode, lives in `.codebrain/graph.db`
387
+ - **QueryEngine** — BFS/DFS traversal for impact analysis, call chains, dead code, cycle detection
388
+
389
+ Everything is local. The database is a single SQLite file in your repo's `.codebrain/` directory (auto-gitignored).
390
+
391
+ ## Real-World Validation
392
+
393
+ Tested on a 1,328-file mixed Python + TypeScript production codebase:
394
+
395
+ | Metric | Result |
396
+ |--------|--------|
397
+ | Files indexed | 1,328 (zero errors) |
398
+ | Symbols extracted | 17,756 |
399
+ | Relationships mapped | 111,793 |
400
+ | Indexing time | 135 seconds |
401
+ | Health score | 93/100 |
402
+ | Impact analysis | 48 dependents traced across 69 files |
403
+ | Implicit contracts | Found co-import pattern in 141/141 files |
404
+ | Tests passing | 794 |
405
+
406
+ ## Requirements
407
+
408
+ - Python 3.11+
409
+ - No internet connection required
410
+ - No API keys required
411
+ - No LLM required
412
+ - Works on Windows, macOS, and Linux
413
+
414
+ ## Development
415
+
416
+ ```bash
417
+ git clone https://github.com/monk0062006/CodeBrain.git
418
+ cd CodeBrain
419
+ pip install -e ".[dev]"
420
+
421
+ pytest tests/ -v # Run tests
422
+ mypy codebrain/ # Type checking
423
+ ruff check codebrain/ # Linting
424
+ pytest --cov=codebrain # Coverage
425
+ ```
426
+
427
+ ## License
428
+
429
+ MIT