codegraph-nav 0.1.0__py3-none-any.whl

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 (41) hide show
  1. codegraph_nav/__init__.py +194 -0
  2. codegraph_nav/ast_grep_analyzer.py +448 -0
  3. codegraph_nav/cli.py +223 -0
  4. codegraph_nav/code_navigator.py +1328 -0
  5. codegraph_nav/code_search.py +1009 -0
  6. codegraph_nav/colors.py +209 -0
  7. codegraph_nav/completions.py +354 -0
  8. codegraph_nav/dart_analyzer.py +301 -0
  9. codegraph_nav/dependency_graph.py +814 -0
  10. codegraph_nav/domain/__init__.py +20 -0
  11. codegraph_nav/domain/routes.py +337 -0
  12. codegraph_nav/domain/schemas.py +229 -0
  13. codegraph_nav/domain/tags.py +87 -0
  14. codegraph_nav/exporters.py +563 -0
  15. codegraph_nav/go_analyzer.py +273 -0
  16. codegraph_nav/graph/__init__.py +72 -0
  17. codegraph_nav/graph/builder.py +409 -0
  18. codegraph_nav/graph/communities.py +402 -0
  19. codegraph_nav/graph/flows.py +311 -0
  20. codegraph_nav/graph/query.py +380 -0
  21. codegraph_nav/graph/schema.py +266 -0
  22. codegraph_nav/graph/search.py +257 -0
  23. codegraph_nav/graph/store.py +517 -0
  24. codegraph_nav/hints.py +195 -0
  25. codegraph_nav/import_resolver.py +891 -0
  26. codegraph_nav/js_ts_analyzer.py +564 -0
  27. codegraph_nav/line_reader.py +664 -0
  28. codegraph_nav/mcp/__init__.py +39 -0
  29. codegraph_nav/mcp/__main__.py +5 -0
  30. codegraph_nav/mcp/server.py +2228 -0
  31. codegraph_nav/py.typed +2 -0
  32. codegraph_nav/ruby_analyzer.py +259 -0
  33. codegraph_nav/rust_analyzer.py +379 -0
  34. codegraph_nav/token_efficient_renderer.py +743 -0
  35. codegraph_nav/watcher.py +382 -0
  36. codegraph_nav-0.1.0.dist-info/METADATA +487 -0
  37. codegraph_nav-0.1.0.dist-info/RECORD +41 -0
  38. codegraph_nav-0.1.0.dist-info/WHEEL +5 -0
  39. codegraph_nav-0.1.0.dist-info/entry_points.txt +4 -0
  40. codegraph_nav-0.1.0.dist-info/licenses/LICENSE +21 -0
  41. codegraph_nav-0.1.0.dist-info/top_level.txt +1 -0
codegraph_nav/cli.py ADDED
@@ -0,0 +1,223 @@
1
+ #!/usr/bin/env python3
2
+ """Unified CLI for codegraph-nav.
3
+
4
+ This module provides a single entry point `codegraph-nav` with subcommands for all
5
+ codegraph-nav functionality:
6
+ - codegraph-nav map (or scan): Generate a code map of a codebase
7
+ - codegraph-nav search: Search for symbols in the code map
8
+ - codegraph-nav read: Read specific lines from files
9
+ - codegraph-nav stats: Show codebase statistics (shortcut for search --stats)
10
+ - codegraph-nav completion: Generate shell completion scripts
11
+ - codegraph-nav watch: Watch for changes and auto-update map
12
+ - codegraph-nav export: Export code map to different formats
13
+
14
+ Example:
15
+ $ codegraph-nav map /path/to/project -o .codegraph.json
16
+ $ codegraph-nav search "UserService" --type class
17
+ $ codegraph-nav read src/api.py 45-60
18
+ $ codegraph-nav stats
19
+ $ codegraph-nav completion bash > ~/.bash_completion.d/codegraph-nav
20
+ $ codegraph-nav watch /path/to/project
21
+ $ codegraph-nav export -f markdown -o docs/codebase.md
22
+ """
23
+
24
+ import argparse
25
+ import sys
26
+
27
+ from . import __version__
28
+ from .code_navigator import add_map_arguments, run_map
29
+ from .code_search import add_search_arguments, run_search
30
+ from .completions import run_completion
31
+ from .exporters import run_export
32
+ from .line_reader import add_read_arguments, run_read
33
+ from .watcher import run_watch
34
+
35
+
36
+ def main():
37
+ """Unified command-line interface for codegraph-nav.
38
+
39
+ Usage:
40
+ codegraph-nav map PATH [-o OUTPUT] [-i IGNORE...] [--compact]
41
+ codegraph-nav search QUERY [--type TYPE] [--file PATTERN] [--limit N]
42
+ codegraph-nav read FILE LINES [-c CONTEXT] [--symbol]
43
+ codegraph-nav stats [-m MAP] [--compact]
44
+ codegraph-nav completion SHELL
45
+ codegraph-nav watch PATH [-o OUTPUT] [--debounce N]
46
+ codegraph-nav export -f FORMAT [-o OUTPUT]
47
+
48
+ Example:
49
+ $ codegraph-nav map /my/project -o .codegraph.json
50
+ $ codegraph-nav search "payment" --type function
51
+ $ codegraph-nav read src/api.py 45-60 -c 2
52
+ $ codegraph-nav stats
53
+ $ codegraph-nav completion bash > ~/.bash_completion.d/codegraph-nav
54
+ $ codegraph-nav watch /my/project
55
+ $ codegraph-nav export -f markdown -o docs/codebase.md
56
+ """
57
+ parser = argparse.ArgumentParser(
58
+ prog="codegraph-nav",
59
+ description="Token-efficient code navigation - reduce token usage by 97%",
60
+ epilog="Run 'codegraph-nav <command> --help' for more information on a command.",
61
+ )
62
+ parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")
63
+
64
+ subparsers = parser.add_subparsers(dest="command", metavar="<command>")
65
+
66
+ # codegraph-nav map / codegraph-nav scan (alias)
67
+ map_parser = subparsers.add_parser(
68
+ "map",
69
+ aliases=["scan"],
70
+ help="Generate a code map of a codebase",
71
+ description="Scan a codebase and generate a JSON index of all symbols.",
72
+ epilog="Example: codegraph-nav map /my/project -o .codegraph.json",
73
+ )
74
+ add_map_arguments(map_parser)
75
+
76
+ # codegraph-nav search
77
+ search_parser = subparsers.add_parser(
78
+ "search",
79
+ help="Search for symbols in the code map",
80
+ description="Search through a code map for symbols, files, and dependencies.",
81
+ epilog='Example: codegraph-nav search "payment" --type function',
82
+ )
83
+ add_search_arguments(search_parser)
84
+
85
+ # codegraph-nav read
86
+ read_parser = subparsers.add_parser(
87
+ "read",
88
+ help="Read specific lines from files",
89
+ description="Read specific lines or ranges from files for token-efficient viewing.",
90
+ epilog="Example: codegraph-nav read src/api.py 45-60 -c 2",
91
+ )
92
+ add_read_arguments(read_parser)
93
+
94
+ # codegraph-nav stats (shortcut for search --stats)
95
+ stats_parser = subparsers.add_parser(
96
+ "stats",
97
+ help="Show codebase statistics (shortcut for search --stats)",
98
+ description="Display statistics about the indexed codebase.",
99
+ epilog="Example: codegraph-nav stats -m .codegraph.json",
100
+ )
101
+ stats_parser.add_argument(
102
+ "-m",
103
+ "--map",
104
+ default=".codegraph.json",
105
+ help="Path to code map file (default: .codegraph.json)",
106
+ )
107
+ stats_parser.add_argument(
108
+ "--compact", action="store_true", help="Output compact JSON (default: pretty-printed)"
109
+ )
110
+ stats_parser.add_argument(
111
+ "-o",
112
+ "--output",
113
+ choices=["json", "table"],
114
+ default="json",
115
+ help="Output format (default: json)",
116
+ )
117
+ stats_parser.add_argument("--no-color", action="store_true", help="Disable colored output")
118
+
119
+ # codegraph-nav completion
120
+ completion_parser = subparsers.add_parser(
121
+ "completion",
122
+ help="Generate shell completion script",
123
+ description="Generate autocompletion script for bash or zsh.",
124
+ epilog="Example: codegraph-nav completion bash > ~/.bash_completion.d/codegraph-nav",
125
+ )
126
+ completion_parser.add_argument(
127
+ "shell",
128
+ choices=["bash", "zsh"],
129
+ help="Shell type (bash or zsh)",
130
+ )
131
+
132
+ # codegraph-nav watch
133
+ watch_parser = subparsers.add_parser(
134
+ "watch",
135
+ help="Watch for changes and auto-update map",
136
+ description="Monitor a codebase for changes and automatically update the code map.",
137
+ epilog="Example: codegraph-nav watch /my/project -o .codegraph.json",
138
+ )
139
+ watch_parser.add_argument("path", help="Path to the codebase root directory")
140
+ watch_parser.add_argument(
141
+ "-o",
142
+ "--output",
143
+ default=".codegraph.json",
144
+ help="Output file path (default: .codegraph.json)",
145
+ )
146
+ watch_parser.add_argument("-i", "--ignore", nargs="*", help="Additional patterns to ignore")
147
+ watch_parser.add_argument(
148
+ "--git-only", action="store_true", help="Only scan files tracked by git"
149
+ )
150
+ watch_parser.add_argument(
151
+ "--use-gitignore", action="store_true", help="Also ignore patterns from .gitignore"
152
+ )
153
+ watch_parser.add_argument(
154
+ "--compact", action="store_true", help="Output compact JSON (default: pretty-printed)"
155
+ )
156
+ watch_parser.add_argument("--no-color", action="store_true", help="Disable colored output")
157
+ watch_parser.add_argument(
158
+ "--debounce",
159
+ type=float,
160
+ default=1.0,
161
+ help="Seconds to wait after change before updating (default: 1.0)",
162
+ )
163
+
164
+ # codegraph-nav export
165
+ export_parser = subparsers.add_parser(
166
+ "export",
167
+ help="Export code map to different formats",
168
+ description="Export the code map to Markdown, HTML, or GraphViz format.",
169
+ epilog="Example: codegraph-nav export -f markdown -o docs/codebase.md",
170
+ )
171
+ export_parser.add_argument(
172
+ "-m",
173
+ "--map",
174
+ default=".codegraph.json",
175
+ help="Path to code map file (default: .codegraph.json)",
176
+ )
177
+ export_parser.add_argument(
178
+ "-f",
179
+ "--format",
180
+ choices=["markdown", "md", "html", "graphviz", "dot"],
181
+ default="markdown",
182
+ help="Export format (default: markdown)",
183
+ )
184
+ export_parser.add_argument("-o", "--output", help="Output file (default: stdout)")
185
+ export_parser.add_argument("--no-color", action="store_true", help="Disable colored output")
186
+
187
+ args = parser.parse_args()
188
+
189
+ if args.command is None:
190
+ parser.print_help()
191
+ sys.exit(0)
192
+
193
+ if args.command in ("map", "scan"):
194
+ run_map(args)
195
+ elif args.command == "search":
196
+ run_search(args)
197
+ elif args.command == "read":
198
+ run_read(args)
199
+ elif args.command == "stats":
200
+ # Convert stats args to search args format
201
+ args.stats = True
202
+ args.query = None
203
+ args.type = None
204
+ args.file = None
205
+ args.files = False
206
+ args.structure = None
207
+ args.deps = None
208
+ args.limit = 10
209
+ args.no_fuzzy = False
210
+ args.check_stale = False
211
+ args.warn_stale = False
212
+ args.since_commit = None
213
+ run_search(args)
214
+ elif args.command == "completion":
215
+ run_completion(args.shell)
216
+ elif args.command == "watch":
217
+ run_watch(args)
218
+ elif args.command == "export":
219
+ run_export(args)
220
+
221
+
222
+ if __name__ == "__main__":
223
+ main()