graphlint 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. graphlint-0.1.0/CHANGELOG.md +22 -0
  2. graphlint-0.1.0/CONTRIBUTING.md +58 -0
  3. graphlint-0.1.0/LICENSE +21 -0
  4. graphlint-0.1.0/MANIFEST.in +14 -0
  5. graphlint-0.1.0/PKG-INFO +181 -0
  6. graphlint-0.1.0/README.md +152 -0
  7. graphlint-0.1.0/README_PYPI.md +152 -0
  8. graphlint-0.1.0/docs/en/api/build.md +94 -0
  9. graphlint-0.1.0/docs/en/api/configure.md +168 -0
  10. graphlint-0.1.0/docs/en/api/exceptions.md +101 -0
  11. graphlint-0.1.0/docs/en/api/query.md +157 -0
  12. graphlint-0.1.0/docs/en/architecture/overview.md +194 -0
  13. graphlint-0.1.0/docs/en/cli/usage.md +157 -0
  14. graphlint-0.1.0/docs/en/guide/agent-integration.md +62 -0
  15. graphlint-0.1.0/docs/en/guide/configuration.md +150 -0
  16. graphlint-0.1.0/docs/en/guide/entry-detection.md +213 -0
  17. graphlint-0.1.0/docs/en/guide/getting-started.md +207 -0
  18. graphlint-0.1.0/docs/en/guide/warnings.md +119 -0
  19. graphlint-0.1.0/docs/en/index.md +64 -0
  20. graphlint-0.1.0/docs/zh/README.md +152 -0
  21. graphlint-0.1.0/docs/zh/api/build.md +94 -0
  22. graphlint-0.1.0/docs/zh/api/configure.md +168 -0
  23. graphlint-0.1.0/docs/zh/api/exceptions.md +101 -0
  24. graphlint-0.1.0/docs/zh/api/query.md +157 -0
  25. graphlint-0.1.0/docs/zh/architecture/overview.md +194 -0
  26. graphlint-0.1.0/docs/zh/cli/usage.md +157 -0
  27. graphlint-0.1.0/docs/zh/guide/agent-integration.md +62 -0
  28. graphlint-0.1.0/docs/zh/guide/configuration.md +150 -0
  29. graphlint-0.1.0/docs/zh/guide/entry-detection.md +213 -0
  30. graphlint-0.1.0/docs/zh/guide/getting-started.md +207 -0
  31. graphlint-0.1.0/docs/zh/guide/warnings.md +119 -0
  32. graphlint-0.1.0/docs/zh/index.md +64 -0
  33. graphlint-0.1.0/graphlint/__init__.py +25 -0
  34. graphlint-0.1.0/graphlint/agent_tools.py +263 -0
  35. graphlint-0.1.0/graphlint/analyzer/__init__.py +1 -0
  36. graphlint-0.1.0/graphlint/analyzer/_ast_visitor.py +361 -0
  37. graphlint-0.1.0/graphlint/analyzer/_graph_algo.py +437 -0
  38. graphlint-0.1.0/graphlint/analyzer/_types.py +65 -0
  39. graphlint-0.1.0/graphlint/analyzer/decorators.py +169 -0
  40. graphlint-0.1.0/graphlint/analyzer/entry_detect.py +509 -0
  41. graphlint-0.1.0/graphlint/analyzer/graph.py +766 -0
  42. graphlint-0.1.0/graphlint/analyzer/imports.py +120 -0
  43. graphlint-0.1.0/graphlint/analyzer/parser.py +133 -0
  44. graphlint-0.1.0/graphlint/analyzer/warnings.py +361 -0
  45. graphlint-0.1.0/graphlint/api.py +419 -0
  46. graphlint-0.1.0/graphlint/cli.py +247 -0
  47. graphlint-0.1.0/graphlint/config/__init__.py +1 -0
  48. graphlint-0.1.0/graphlint/config/defaults.py +129 -0
  49. graphlint-0.1.0/graphlint/config/manager.py +222 -0
  50. graphlint-0.1.0/graphlint/exceptions.py +43 -0
  51. graphlint-0.1.0/graphlint/i18n/__init__.py +125 -0
  52. graphlint-0.1.0/graphlint/i18n/en.py +75 -0
  53. graphlint-0.1.0/graphlint/i18n/zh_CN.py +75 -0
  54. graphlint-0.1.0/graphlint/incremental/__init__.py +1 -0
  55. graphlint-0.1.0/graphlint/incremental/_db_ops.py +438 -0
  56. graphlint-0.1.0/graphlint/incremental/indexer.py +343 -0
  57. graphlint-0.1.0/graphlint/params.py +313 -0
  58. graphlint-0.1.0/graphlint/query/__init__.py +1 -0
  59. graphlint-0.1.0/graphlint/query/engine.py +436 -0
  60. graphlint-0.1.0/graphlint/query/formatter.py +332 -0
  61. graphlint-0.1.0/graphlint/query/volume.py +92 -0
  62. graphlint-0.1.0/graphlint/storage/__init__.py +1 -0
  63. graphlint-0.1.0/graphlint/storage/db.py +165 -0
  64. graphlint-0.1.0/graphlint/storage/hashing.py +54 -0
  65. graphlint-0.1.0/graphlint/storage/schema.py +140 -0
  66. graphlint-0.1.0/graphlint.egg-info/PKG-INFO +181 -0
  67. graphlint-0.1.0/graphlint.egg-info/SOURCES.txt +100 -0
  68. graphlint-0.1.0/graphlint.egg-info/dependency_links.txt +1 -0
  69. graphlint-0.1.0/graphlint.egg-info/entry_points.txt +2 -0
  70. graphlint-0.1.0/graphlint.egg-info/requires.txt +4 -0
  71. graphlint-0.1.0/graphlint.egg-info/top_level.txt +1 -0
  72. graphlint-0.1.0/pyproject.toml +65 -0
  73. graphlint-0.1.0/setup.cfg +4 -0
  74. graphlint-0.1.0/tests/__init__.py +1 -0
  75. graphlint-0.1.0/tests/integration/__init__.py +0 -0
  76. graphlint-0.1.0/tests/integration/test_api.py +105 -0
  77. graphlint-0.1.0/tests/integration/test_cli.py +107 -0
  78. graphlint-0.1.0/tests/integration/test_data_transfer.py +148 -0
  79. graphlint-0.1.0/tests/integration/test_dead_code_query.py +75 -0
  80. graphlint-0.1.0/tests/integration/test_full_pipeline.py +102 -0
  81. graphlint-0.1.0/tests/integration/test_incremental.py +86 -0
  82. graphlint-0.1.0/tests/integration/test_json_output.py +80 -0
  83. graphlint-0.1.0/tests/performance/__init__.py +0 -0
  84. graphlint-0.1.0/tests/performance/test_large_codebase.py +82 -0
  85. graphlint-0.1.0/tests/unit/__init__.py +0 -0
  86. graphlint-0.1.0/tests/unit/test_config.py +178 -0
  87. graphlint-0.1.0/tests/unit/test_db.py +165 -0
  88. graphlint-0.1.0/tests/unit/test_decorators.py +110 -0
  89. graphlint-0.1.0/tests/unit/test_engine.py +135 -0
  90. graphlint-0.1.0/tests/unit/test_entry_detect.py +200 -0
  91. graphlint-0.1.0/tests/unit/test_exceptions.py +54 -0
  92. graphlint-0.1.0/tests/unit/test_formatter.py +239 -0
  93. graphlint-0.1.0/tests/unit/test_graph.py +170 -0
  94. graphlint-0.1.0/tests/unit/test_hashing.py +135 -0
  95. graphlint-0.1.0/tests/unit/test_i18n.py +100 -0
  96. graphlint-0.1.0/tests/unit/test_imports.py +93 -0
  97. graphlint-0.1.0/tests/unit/test_mock_boundary.py +159 -0
  98. graphlint-0.1.0/tests/unit/test_params.py +88 -0
  99. graphlint-0.1.0/tests/unit/test_parser.py +158 -0
  100. graphlint-0.1.0/tests/unit/test_schema.py +151 -0
  101. graphlint-0.1.0/tests/unit/test_volume.py +105 -0
  102. graphlint-0.1.0/tests/unit/test_warnings.py +166 -0
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-07-01
6
+
7
+ ### Added
8
+ - Initial release
9
+ - AST-based Python source code parsing (classes, functions, methods, variables, fields)
10
+ - Dependency graph construction with 5 edge types (read, write, call, inherit, decorate)
11
+ - 8 built-in entry point detection rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest)
12
+ - Custom entry point rules via AST pattern matching
13
+ - 11 warning types (unused_import, dynamic_import, circular_ref, syntax_error, write_only, deprecated_usage, dead_code, type_mismatch, unresolved_ref, unused_variable, file_too_large)
14
+ - Incremental indexing with SHA256-based change detection
15
+ - Adaptive output volume strategy (full, index, truncated)
16
+ - Internationalization (English and Simplified Chinese)
17
+ - CLI interface (`graphlint query`, `graphlint build`, `graphlint config`)
18
+ - Python API (`query()`, `build()`, `configure()`)
19
+ - SQLite persistence with cross-platform file locking
20
+ - Parallel file parsing via ProcessPoolExecutor
21
+ - Configuration management with dot-notation key access
22
+ - Comprehensive test suite (unit, integration, performance)
@@ -0,0 +1,58 @@
1
+ # Contributing to graphlint
2
+
3
+ Thank you for your interest in contributing! This document outlines the process for contributing to graphlint.
4
+
5
+ ## Getting Started
6
+
7
+ 1. Fork the repository on GitHub
8
+ 2. Clone your fork locally
9
+ 3. Create a virtual environment and install dev dependencies:
10
+ ```bash
11
+ python -m venv env
12
+ source env/bin/activate # or env/Scripts/activate on Windows
13
+ pip install -e ".[dev]"
14
+ ```
15
+ 4. Create a branch for your changes
16
+
17
+ ## Development Workflow
18
+
19
+ - Write code that follows [PEP 8](https://peps.python.org/pep-0008/) style
20
+ - Add type annotations for all public functions and methods
21
+ - Write tests for new functionality
22
+ - Ensure all existing tests pass before submitting a PR
23
+
24
+ ## Running Checks
25
+
26
+ ```bash
27
+ # Run tests
28
+ pytest
29
+
30
+ # Run with coverage
31
+ pytest --cov=graphlint
32
+
33
+ # Type checking
34
+ mypy graphlint/
35
+
36
+ # Lint
37
+ ruff check graphlint/ tests/
38
+ ```
39
+
40
+ ## Pull Request Process
41
+
42
+ 1. Update the README or documentation if your change affects the public API
43
+ 2. Add an entry to CHANGELOG.md under the "Unreleased" section
44
+ 3. Ensure all checks pass (tests, mypy, ruff)
45
+ 4. Submit your pull request with a clear description of the changes
46
+
47
+ ## Code Style
48
+
49
+ - Use 4 spaces for indentation (no tabs)
50
+ - Maximum line length: 120 characters
51
+ - Use `from __future__ import annotations` for modern type hints
52
+ - Prefer `Optional[X]` over `X | None` for Python 3.9 compatibility
53
+ - Module-level docstrings should briefly describe the module's purpose
54
+ - Public functions and classes should have docstrings
55
+
56
+ ## Questions?
57
+
58
+ Open an issue on [GitHub](https://github.com/AngelosZou/graphlint/issues) if you have questions or need clarification.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yutong Zou
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,14 @@
1
+ include pyproject.toml
2
+ include README.md
3
+ include docs/zh/README.md
4
+ include LICENSE
5
+ include CHANGELOG.md
6
+ include CONTRIBUTING.md
7
+
8
+ recursive-include graphlint *.py
9
+ recursive-include docs *.md
10
+ recursive-include tests *.py
11
+
12
+ prune tests/__pycache__
13
+ prune .graphlint
14
+ prune .pytest_cache
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphlint
3
+ Version: 0.1.0
4
+ Summary: A static analysis tool for identifying dead code in a codebase. It provides Python API and CLI for use by agents.
5
+ Author-email: Yutong Zou <yutong.zou.24@alumni.ucl.ac.uk>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AngelosZou/graphlint
8
+ Project-URL: Repository, https://github.com/AngelosZou/graphlint
9
+ Project-URL: Issues, https://github.com/AngelosZou/graphlint/issues
10
+ Keywords: graph,dependency-graph,code-analysis,dead-code,circular-dependency,import-checker,static-analysis,lint
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Quality Assurance
21
+ Classifier: Topic :: Software Development :: Documentation
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # graphlint
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/graphlint)](https://pypi.org/project/graphlint/)
33
+ [![Python](https://img.shields.io/pypi/pyversions/graphlint)](https://pypi.org/project/graphlint/)
34
+ [![License](https://img.shields.io/pypi/l/graphlint)](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
35
+
36
+ [![en](https://img.shields.io/badge/lang-en-red.svg)](https://github.com/AngelosZou/graphlint/blob/main/README.md)
37
+ [![zh](https://img.shields.io/badge/lang-zh--CN-blue.svg)](https://github.com/AngelosZou/graphlint/blob/main/docs/zh/README.md)
38
+
39
+ **Dead code detection for AI-generated Python codebases.**
40
+
41
+ AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
42
+
43
+ ## Features
44
+
45
+ - **Dead code detection** — finds components unreachable from any entry point via graph traversal
46
+ - **AST parsing** — extracts classes, functions, methods, variables, and fields
47
+ - **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
48
+ - **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
49
+ - **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
50
+ - **Incremental indexing** — SHA256-based change detection parses only modified files
51
+ - **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
52
+ - **Zero runtime dependencies** — only requires the Python standard library
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ pip install graphlint
58
+ ```
59
+
60
+ **Requirements:** Python >= 3.9
61
+
62
+ ## Quick Start
63
+
64
+ ### Agent Integration
65
+
66
+ Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
67
+
68
+ ```bash
69
+ # Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
70
+ graphlint install
71
+
72
+ # Remove graphlint prompt from agent tools
73
+ graphlint uninstall
74
+ ```
75
+
76
+ Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md).
77
+
78
+ ### CLI
79
+
80
+ ```bash
81
+ # Find dead code in current directory
82
+ graphlint query --warn-types "dead_code"
83
+
84
+ # Full analysis with JSON output
85
+ graphlint query --json
86
+
87
+ # View a specific graph detail
88
+ graphlint query -g 1 --detail full
89
+
90
+ # Rebuild index
91
+ graphlint build --force
92
+
93
+ # Configure
94
+ graphlint config show
95
+ graphlint config set --key lang --value en
96
+ ```
97
+
98
+ ### Python API
99
+
100
+ ```python
101
+ from graphlint.api import query
102
+
103
+ # Find dead code components
104
+ result = query(warn_types="dead_code", json_output=True)
105
+
106
+ # Full dependency graph analysis
107
+ result = query(include_tests=True, json_output=True)
108
+ ```
109
+
110
+ ## Warning Types
111
+
112
+ | Warning | Description |
113
+ |---------|-------------|
114
+ | `unused_import` | Imported module or name is never used |
115
+ | `dynamic_import` | Dynamic import via `importlib` or `__import__` |
116
+ | `circular_ref` | Circular dependency between functions/classes |
117
+ | `syntax_error` | File contains a syntax error |
118
+ | `write_only` | Variable is written but never read |
119
+ | `deprecated_usage` | Usage of a deprecated function/class |
120
+ | `dead_code` | Component unreachable from any entry point |
121
+ | `type_mismatch` | Suspicious type annotations |
122
+ | `unresolved_ref` | Reference to an undefined name |
123
+ | `unused_variable` | Variable is defined but never used |
124
+ | `file_too_large` | File exceeds the configured size limit |
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ # Clone the repository
130
+ git clone https://github.com/AngelosZou/graphlint.git
131
+ cd graphlint
132
+
133
+ # Create a virtual environment
134
+ python -m venv env
135
+ env/Scripts/activate # Windows
136
+ source env/bin/activate # Unix
137
+
138
+ # Install dev dependencies
139
+ pip install -e ".[dev]"
140
+
141
+ # Run tests
142
+ pytest
143
+
144
+ # Run with coverage
145
+ pytest --cov=graphlint
146
+
147
+ # Run type checking
148
+ mypy graphlint/
149
+
150
+ # Run linting
151
+ ruff check graphlint/ tests/
152
+ ```
153
+
154
+ ## Configuration
155
+
156
+ Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
157
+
158
+ See `graphlint config show` for the full default configuration.
159
+
160
+ ## Documentation
161
+
162
+ Full documentation is available in the [docs/](https://github.com/AngelosZou/graphlint/tree/main/docs/) directory:
163
+
164
+ - [Getting Started](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/getting-started.md)
165
+ - [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md)
166
+ - [Configuration Guide](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/configuration.md)
167
+ - [Entry Point Detection](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/entry-detection.md)
168
+ - [Warning Reference](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/warnings.md)
169
+ - [CLI Usage](https://github.com/AngelosZou/graphlint/blob/main/docs/en/cli/usage.md)
170
+ - [Architecture Overview](https://github.com/AngelosZou/graphlint/blob/main/docs/en/architecture/overview.md)
171
+ - [Python API](https://github.com/AngelosZou/graphlint/tree/main/docs/en/api/)
172
+
173
+ ## License
174
+
175
+ MIT — see [LICENSE](https://github.com/AngelosZou/graphlint/blob/main/LICENSE) for details.
176
+
177
+ ## Links
178
+
179
+ - [GitHub Repository](https://github.com/AngelosZou/graphlint)
180
+ - [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
181
+ - [PyPI Package](https://pypi.org/project/graphlint/)
@@ -0,0 +1,152 @@
1
+ # graphlint
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/graphlint)](https://pypi.org/project/graphlint/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/graphlint)](https://pypi.org/project/graphlint/)
5
+ [![License](https://img.shields.io/pypi/l/graphlint)](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
6
+
7
+ [![en](https://img.shields.io/badge/lang-en-red.svg)](README.md)
8
+ [![zh](https://img.shields.io/badge/lang-zh--CN-blue.svg)](docs/zh/README.md)
9
+
10
+ **Dead code detection for AI-generated Python codebases.**
11
+
12
+ AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
13
+
14
+ ## Features
15
+
16
+ - **Dead code detection** — finds components unreachable from any entry point via graph traversal
17
+ - **AST parsing** — extracts classes, functions, methods, variables, and fields
18
+ - **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
19
+ - **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
20
+ - **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
21
+ - **Incremental indexing** — SHA256-based change detection parses only modified files
22
+ - **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
23
+ - **Zero runtime dependencies** — only requires the Python standard library
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install graphlint
29
+ ```
30
+
31
+ **Requirements:** Python >= 3.9
32
+
33
+ ## Quick Start
34
+
35
+ ### Agent Integration
36
+
37
+ Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
38
+
39
+ ```bash
40
+ # Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
41
+ graphlint install
42
+
43
+ # Remove graphlint prompt from agent tools
44
+ graphlint uninstall
45
+ ```
46
+
47
+ Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](docs/en/guide/agent-integration.md).
48
+
49
+ ### CLI
50
+
51
+ ```bash
52
+ # Find dead code in current directory
53
+ graphlint query --warn-types "dead_code"
54
+
55
+ # Full analysis with JSON output
56
+ graphlint query --json
57
+
58
+ # View a specific graph detail
59
+ graphlint query -g 1 --detail full
60
+
61
+ # Rebuild index
62
+ graphlint build --force
63
+
64
+ # Configure
65
+ graphlint config show
66
+ graphlint config set --key lang --value en
67
+ ```
68
+
69
+ ### Python API
70
+
71
+ ```python
72
+ from graphlint.api import query
73
+
74
+ # Find dead code components
75
+ result = query(warn_types="dead_code", json_output=True)
76
+
77
+ # Full dependency graph analysis
78
+ result = query(include_tests=True, json_output=True)
79
+ ```
80
+
81
+ ## Warning Types
82
+
83
+ | Warning | Description |
84
+ |---------|-------------|
85
+ | `unused_import` | Imported module or name is never used |
86
+ | `dynamic_import` | Dynamic import via `importlib` or `__import__` |
87
+ | `circular_ref` | Circular dependency between functions/classes |
88
+ | `syntax_error` | File contains a syntax error |
89
+ | `write_only` | Variable is written but never read |
90
+ | `deprecated_usage` | Usage of a deprecated function/class |
91
+ | `dead_code` | Component unreachable from any entry point |
92
+ | `type_mismatch` | Suspicious type annotations |
93
+ | `unresolved_ref` | Reference to an undefined name |
94
+ | `unused_variable` | Variable is defined but never used |
95
+ | `file_too_large` | File exceeds the configured size limit |
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ # Clone the repository
101
+ git clone https://github.com/AngelosZou/graphlint.git
102
+ cd graphlint
103
+
104
+ # Create a virtual environment
105
+ python -m venv env
106
+ env/Scripts/activate # Windows
107
+ source env/bin/activate # Unix
108
+
109
+ # Install dev dependencies
110
+ pip install -e ".[dev]"
111
+
112
+ # Run tests
113
+ pytest
114
+
115
+ # Run with coverage
116
+ pytest --cov=graphlint
117
+
118
+ # Run type checking
119
+ mypy graphlint/
120
+
121
+ # Run linting
122
+ ruff check graphlint/ tests/
123
+ ```
124
+
125
+ ## Configuration
126
+
127
+ Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
128
+
129
+ See `graphlint config show` for the full default configuration.
130
+
131
+ ## Documentation
132
+
133
+ Full documentation is available in the [docs/](docs/) directory:
134
+
135
+ - [Getting Started](docs/en/guide/getting-started.md)
136
+ - [Agent Integration](docs/en/guide/agent-integration.md)
137
+ - [Configuration Guide](docs/en/guide/configuration.md)
138
+ - [Entry Point Detection](docs/en/guide/entry-detection.md)
139
+ - [Warning Reference](docs/en/guide/warnings.md)
140
+ - [CLI Usage](docs/en/cli/usage.md)
141
+ - [Architecture Overview](docs/en/architecture/overview.md)
142
+ - [Python API](docs/en/api/)
143
+
144
+ ## License
145
+
146
+ MIT — see [LICENSE](LICENSE) for details.
147
+
148
+ ## Links
149
+
150
+ - [GitHub Repository](https://github.com/AngelosZou/graphlint)
151
+ - [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
152
+ - [PyPI Package](https://pypi.org/project/graphlint/)
@@ -0,0 +1,152 @@
1
+ # graphlint
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/graphlint)](https://pypi.org/project/graphlint/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/graphlint)](https://pypi.org/project/graphlint/)
5
+ [![License](https://img.shields.io/pypi/l/graphlint)](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
6
+
7
+ [![en](https://img.shields.io/badge/lang-en-red.svg)](https://github.com/AngelosZou/graphlint/blob/main/README.md)
8
+ [![zh](https://img.shields.io/badge/lang-zh--CN-blue.svg)](https://github.com/AngelosZou/graphlint/blob/main/docs/zh/README.md)
9
+
10
+ **Dead code detection for AI-generated Python codebases.**
11
+
12
+ AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
13
+
14
+ ## Features
15
+
16
+ - **Dead code detection** — finds components unreachable from any entry point via graph traversal
17
+ - **AST parsing** — extracts classes, functions, methods, variables, and fields
18
+ - **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
19
+ - **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
20
+ - **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
21
+ - **Incremental indexing** — SHA256-based change detection parses only modified files
22
+ - **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
23
+ - **Zero runtime dependencies** — only requires the Python standard library
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install graphlint
29
+ ```
30
+
31
+ **Requirements:** Python >= 3.9
32
+
33
+ ## Quick Start
34
+
35
+ ### Agent Integration
36
+
37
+ Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
38
+
39
+ ```bash
40
+ # Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
41
+ graphlint install
42
+
43
+ # Remove graphlint prompt from agent tools
44
+ graphlint uninstall
45
+ ```
46
+
47
+ Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md).
48
+
49
+ ### CLI
50
+
51
+ ```bash
52
+ # Find dead code in current directory
53
+ graphlint query --warn-types "dead_code"
54
+
55
+ # Full analysis with JSON output
56
+ graphlint query --json
57
+
58
+ # View a specific graph detail
59
+ graphlint query -g 1 --detail full
60
+
61
+ # Rebuild index
62
+ graphlint build --force
63
+
64
+ # Configure
65
+ graphlint config show
66
+ graphlint config set --key lang --value en
67
+ ```
68
+
69
+ ### Python API
70
+
71
+ ```python
72
+ from graphlint.api import query
73
+
74
+ # Find dead code components
75
+ result = query(warn_types="dead_code", json_output=True)
76
+
77
+ # Full dependency graph analysis
78
+ result = query(include_tests=True, json_output=True)
79
+ ```
80
+
81
+ ## Warning Types
82
+
83
+ | Warning | Description |
84
+ |---------|-------------|
85
+ | `unused_import` | Imported module or name is never used |
86
+ | `dynamic_import` | Dynamic import via `importlib` or `__import__` |
87
+ | `circular_ref` | Circular dependency between functions/classes |
88
+ | `syntax_error` | File contains a syntax error |
89
+ | `write_only` | Variable is written but never read |
90
+ | `deprecated_usage` | Usage of a deprecated function/class |
91
+ | `dead_code` | Component unreachable from any entry point |
92
+ | `type_mismatch` | Suspicious type annotations |
93
+ | `unresolved_ref` | Reference to an undefined name |
94
+ | `unused_variable` | Variable is defined but never used |
95
+ | `file_too_large` | File exceeds the configured size limit |
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ # Clone the repository
101
+ git clone https://github.com/AngelosZou/graphlint.git
102
+ cd graphlint
103
+
104
+ # Create a virtual environment
105
+ python -m venv env
106
+ env/Scripts/activate # Windows
107
+ source env/bin/activate # Unix
108
+
109
+ # Install dev dependencies
110
+ pip install -e ".[dev]"
111
+
112
+ # Run tests
113
+ pytest
114
+
115
+ # Run with coverage
116
+ pytest --cov=graphlint
117
+
118
+ # Run type checking
119
+ mypy graphlint/
120
+
121
+ # Run linting
122
+ ruff check graphlint/ tests/
123
+ ```
124
+
125
+ ## Configuration
126
+
127
+ Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
128
+
129
+ See `graphlint config show` for the full default configuration.
130
+
131
+ ## Documentation
132
+
133
+ Full documentation is available in the [docs/](https://github.com/AngelosZou/graphlint/tree/main/docs/) directory:
134
+
135
+ - [Getting Started](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/getting-started.md)
136
+ - [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md)
137
+ - [Configuration Guide](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/configuration.md)
138
+ - [Entry Point Detection](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/entry-detection.md)
139
+ - [Warning Reference](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/warnings.md)
140
+ - [CLI Usage](https://github.com/AngelosZou/graphlint/blob/main/docs/en/cli/usage.md)
141
+ - [Architecture Overview](https://github.com/AngelosZou/graphlint/blob/main/docs/en/architecture/overview.md)
142
+ - [Python API](https://github.com/AngelosZou/graphlint/tree/main/docs/en/api/)
143
+
144
+ ## License
145
+
146
+ MIT — see [LICENSE](https://github.com/AngelosZou/graphlint/blob/main/LICENSE) for details.
147
+
148
+ ## Links
149
+
150
+ - [GitHub Repository](https://github.com/AngelosZou/graphlint)
151
+ - [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
152
+ - [PyPI Package](https://pypi.org/project/graphlint/)