codegraphcontext-rust 0.9.24__cp314-cp314-win_amd64.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 (112) hide show
  1. codegraphcontext/__init__.py +2 -0
  2. codegraphcontext/__main__.py +5 -0
  3. codegraphcontext/_cgc_rust.cp314-win_amd64.pyd +4 -0
  4. codegraphcontext/cli/__init__.py +1 -0
  5. codegraphcontext/cli/cli_helpers.py +774 -0
  6. codegraphcontext/cli/config_manager.py +1051 -0
  7. codegraphcontext/cli/entry.py +21 -0
  8. codegraphcontext/cli/main.py +2386 -0
  9. codegraphcontext/cli/registry_commands.py +404 -0
  10. codegraphcontext/cli/setup_macos.py +93 -0
  11. codegraphcontext/cli/setup_wizard.py +991 -0
  12. codegraphcontext/cli/visualizer.py +50 -0
  13. codegraphcontext/core/__init__.py +165 -0
  14. codegraphcontext/core/bundle_registry.py +181 -0
  15. codegraphcontext/core/cgc_bundle.py +858 -0
  16. codegraphcontext/core/cgcignore.py +118 -0
  17. codegraphcontext/core/database.py +273 -0
  18. codegraphcontext/core/database_falkordb.py +480 -0
  19. codegraphcontext/core/database_falkordb_remote.py +199 -0
  20. codegraphcontext/core/database_kuzu.py +636 -0
  21. codegraphcontext/core/falkor_worker.py +132 -0
  22. codegraphcontext/core/jobs.py +132 -0
  23. codegraphcontext/core/watcher.py +260 -0
  24. codegraphcontext/prompts.py +125 -0
  25. codegraphcontext/server.py +471 -0
  26. codegraphcontext/tool_definitions.py +220 -0
  27. codegraphcontext/tools/__init__.py +0 -0
  28. codegraphcontext/tools/advanced_language_query_tool.py +103 -0
  29. codegraphcontext/tools/code_finder.py +1160 -0
  30. codegraphcontext/tools/graph_builder.py +337 -0
  31. codegraphcontext/tools/handlers/analysis_handlers.py +114 -0
  32. codegraphcontext/tools/handlers/indexing_handlers.py +116 -0
  33. codegraphcontext/tools/handlers/management_handlers.py +339 -0
  34. codegraphcontext/tools/handlers/query_handlers.py +83 -0
  35. codegraphcontext/tools/handlers/watcher_handlers.py +83 -0
  36. codegraphcontext/tools/indexing/__init__.py +1 -0
  37. codegraphcontext/tools/indexing/angular_routes.py +396 -0
  38. codegraphcontext/tools/indexing/cgc_wiki_cli.py +1334 -0
  39. codegraphcontext/tools/indexing/constants.py +70 -0
  40. codegraphcontext/tools/indexing/context_generator.py +461 -0
  41. codegraphcontext/tools/indexing/discovery.py +64 -0
  42. codegraphcontext/tools/indexing/engine.py +114 -0
  43. codegraphcontext/tools/indexing/execution_flows.py +355 -0
  44. codegraphcontext/tools/indexing/module_grouping.py +551 -0
  45. codegraphcontext/tools/indexing/noise_filter.py +131 -0
  46. codegraphcontext/tools/indexing/op_param_extraction.py +287 -0
  47. codegraphcontext/tools/indexing/persistence/__init__.py +3 -0
  48. codegraphcontext/tools/indexing/persistence/duckdb_writer.py +1116 -0
  49. codegraphcontext/tools/indexing/persistence/parquet_loader.py +643 -0
  50. codegraphcontext/tools/indexing/persistence/writer.py +1562 -0
  51. codegraphcontext/tools/indexing/pipeline.py +171 -0
  52. codegraphcontext/tools/indexing/pre_scan.py +105 -0
  53. codegraphcontext/tools/indexing/rationale_extraction.py +154 -0
  54. codegraphcontext/tools/indexing/resolution/__init__.py +8 -0
  55. codegraphcontext/tools/indexing/resolution/calls.py +253 -0
  56. codegraphcontext/tools/indexing/resolution/inheritance.py +91 -0
  57. codegraphcontext/tools/indexing/route_extraction.py +659 -0
  58. codegraphcontext/tools/indexing/sanitize.py +41 -0
  59. codegraphcontext/tools/indexing/schema.py +79 -0
  60. codegraphcontext/tools/indexing/schema_contract.py +44 -0
  61. codegraphcontext/tools/indexing/scip_pipeline.py +140 -0
  62. codegraphcontext/tools/languages/c.py +563 -0
  63. codegraphcontext/tools/languages/cpp.py +616 -0
  64. codegraphcontext/tools/languages/csharp.py +551 -0
  65. codegraphcontext/tools/languages/dart.py +378 -0
  66. codegraphcontext/tools/languages/elixir.py +460 -0
  67. codegraphcontext/tools/languages/go.py +499 -0
  68. codegraphcontext/tools/languages/haskell.py +426 -0
  69. codegraphcontext/tools/languages/java.py +500 -0
  70. codegraphcontext/tools/languages/javascript.py +589 -0
  71. codegraphcontext/tools/languages/kotlin.py +640 -0
  72. codegraphcontext/tools/languages/perl.py +260 -0
  73. codegraphcontext/tools/languages/php.py +519 -0
  74. codegraphcontext/tools/languages/python.py +578 -0
  75. codegraphcontext/tools/languages/ruby.py +537 -0
  76. codegraphcontext/tools/languages/rust.py +295 -0
  77. codegraphcontext/tools/languages/scala.py +519 -0
  78. codegraphcontext/tools/languages/swift.py +491 -0
  79. codegraphcontext/tools/languages/typescript.py +606 -0
  80. codegraphcontext/tools/languages/typescriptjsx.py +151 -0
  81. codegraphcontext/tools/package_resolver.py +472 -0
  82. codegraphcontext/tools/query_tool_languages/c_toolkit.py +5 -0
  83. codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +87 -0
  84. codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +5 -0
  85. codegraphcontext/tools/query_tool_languages/dart_toolkit.py +5 -0
  86. codegraphcontext/tools/query_tool_languages/go_toolkit.py +5 -0
  87. codegraphcontext/tools/query_tool_languages/haskell_toolkit.py +5 -0
  88. codegraphcontext/tools/query_tool_languages/java_toolkit.py +5 -0
  89. codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +5 -0
  90. codegraphcontext/tools/query_tool_languages/perl_toolkit.py +5 -0
  91. codegraphcontext/tools/query_tool_languages/python_toolkit.py +5 -0
  92. codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +5 -0
  93. codegraphcontext/tools/query_tool_languages/rust_toolkit.py +5 -0
  94. codegraphcontext/tools/query_tool_languages/scala_toolkit.py +5 -0
  95. codegraphcontext/tools/query_tool_languages/swift_toolkit.py +5 -0
  96. codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +5 -0
  97. codegraphcontext/tools/scip_indexer.py +467 -0
  98. codegraphcontext/tools/scip_pb2.py +2455 -0
  99. codegraphcontext/tools/system.py +133 -0
  100. codegraphcontext/tools/tree_sitter_parser.py +103 -0
  101. codegraphcontext/utils/debug_log.py +90 -0
  102. codegraphcontext/utils/path_ignore.py +55 -0
  103. codegraphcontext/utils/repo_path.py +27 -0
  104. codegraphcontext/utils/tree_sitter_manager.py +285 -0
  105. codegraphcontext/utils/visualize_graph.py +0 -0
  106. codegraphcontext/viz/server.py +282 -0
  107. codegraphcontext_rust-0.9.24.dist-info/METADATA +543 -0
  108. codegraphcontext_rust-0.9.24.dist-info/RECORD +112 -0
  109. codegraphcontext_rust-0.9.24.dist-info/WHEEL +4 -0
  110. codegraphcontext_rust-0.9.24.dist-info/entry_points.txt +4 -0
  111. codegraphcontext_rust-0.9.24.dist-info/licenses/LICENSE +21 -0
  112. codegraphcontext_rust-0.9.24.dist-info/sboms/cgc-python.cyclonedx.json +2302 -0
@@ -0,0 +1,114 @@
1
+ """
2
+ Engine adapter: selects Rust or Python backend for parsing + resolution.
3
+
4
+ The Rust backend (_cgc_rust) provides significant performance improvements
5
+ for file parsing and parallel processing. If unavailable, falls back to
6
+ the existing Python implementation transparently.
7
+
8
+ Set CGC_USE_PYTHON_PARSER=1 to force Python backend for debugging.
9
+ """
10
+ import os
11
+ import logging
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ RUST_AVAILABLE = False
16
+
17
+ if not os.environ.get("CGC_USE_PYTHON_PARSER"):
18
+ try:
19
+ from codegraphcontext._cgc_rust import (
20
+ parse_file as _rust_parse_file,
21
+ parse_files_parallel as _rust_parse_files_parallel,
22
+ pre_scan_for_imports as _rust_pre_scan,
23
+ parse_and_prescan as _rust_parse_and_prescan,
24
+ resolve_call_groups as _rust_resolve_calls,
25
+ resolve_inheritance as _rust_resolve_inheritance,
26
+ sanitize_props as _rust_sanitize_props,
27
+ )
28
+ RUST_AVAILABLE = True
29
+ logger.info("Rust parsing engine loaded successfully")
30
+ except ImportError:
31
+ logger.debug("Rust parsing engine not available, using Python fallback")
32
+
33
+
34
+ def parse_file(path, lang, is_dependency=False, index_source=False,
35
+ parser_wrapper=None, **kwargs):
36
+ """Parse a single file. Uses Rust if available, else Python."""
37
+ if RUST_AVAILABLE and lang in _RUST_SUPPORTED_LANGS:
38
+ return _rust_parse_file(str(path), lang, is_dependency, index_source)
39
+
40
+ # Python fallback
41
+ if parser_wrapper is None:
42
+ raise ValueError("parser_wrapper required for Python fallback")
43
+ return parser_wrapper.parse(path, is_dependency, index_source=index_source, **kwargs)
44
+
45
+
46
+ def parse_files_parallel(file_specs, num_threads=None, index_source=False):
47
+ """Parse multiple files in parallel using Rust.
48
+
49
+ Args:
50
+ file_specs: list of (path_str, lang, is_dependency) tuples
51
+ num_threads: optional thread count (0 = auto)
52
+ index_source: if True, extract docstrings and source bodies
53
+
54
+ Returns:
55
+ list of file_data dicts
56
+
57
+ Raises:
58
+ RuntimeError if Rust engine not available
59
+ """
60
+ if not RUST_AVAILABLE:
61
+ raise RuntimeError("Rust engine required for parallel parsing")
62
+
63
+ return _rust_parse_files_parallel(file_specs, num_threads, index_source)
64
+
65
+
66
+ def pre_scan_for_imports(file_specs):
67
+ """Pre-scan files to build imports_map.
68
+
69
+ Args:
70
+ file_specs: list of (path_str, extension) tuples
71
+
72
+ Returns:
73
+ dict {symbol_name: [file_path, ...]}
74
+
75
+ Raises:
76
+ RuntimeError if Rust engine not available
77
+ """
78
+ if not RUST_AVAILABLE:
79
+ raise RuntimeError("Rust engine required for pre_scan_for_imports")
80
+
81
+ return _rust_pre_scan(file_specs)
82
+
83
+
84
+ def resolve_call_groups(all_file_data, imports_map, skip_external=False, with_unresolved=False):
85
+ """Resolve function calls into 6-category groups using Rust.
86
+
87
+ With ``with_unresolved=True`` returns ``(groups, unresolved)`` where
88
+ ``unresolved`` lists the calls that produced no edge and why.
89
+ """
90
+ if not RUST_AVAILABLE:
91
+ raise RuntimeError("Rust engine required for resolve_call_groups")
92
+ return _rust_resolve_calls(all_file_data, imports_map, skip_external, with_unresolved)
93
+
94
+
95
+ def resolve_inheritance(all_file_data, imports_map):
96
+ """Resolve inheritance links using Rust."""
97
+ if not RUST_AVAILABLE:
98
+ raise RuntimeError("Rust engine required for resolve_inheritance")
99
+ return _rust_resolve_inheritance(all_file_data, imports_map)
100
+
101
+
102
+ def sanitize_props(props):
103
+ """Sanitize properties for graph DB storage using Rust."""
104
+ if not RUST_AVAILABLE:
105
+ raise RuntimeError("Rust engine required for sanitize_props")
106
+ return _rust_sanitize_props(props)
107
+
108
+
109
+ # All 19 languages supported by the Rust engine
110
+ _RUST_SUPPORTED_LANGS = {
111
+ "python", "javascript", "typescript", "tsx", "go", "java", "cpp",
112
+ "c", "rust", "ruby", "c_sharp", "php", "kotlin", "perl",
113
+ "scala", "swift", "haskell", "dart", "elixir",
114
+ }
@@ -0,0 +1,355 @@
1
+ """Detect execution flows (entry points → call chain traces).
2
+
3
+ An execution flow starts at an "entry point" (API handler, main function,
4
+ test function, CLI command, scheduled task) and traces through the call
5
+ graph via BFS to show the full execution path.
6
+
7
+ This gives AI agents/LLMs a "what happens when X is called" view.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ import os
14
+ from collections import deque
15
+ from pathlib import Path
16
+ from typing import Any, Dict, List, Optional, Set, Tuple
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ # ── Entry point detection patterns ──────────────────────────────────
21
+
22
+ # Function name patterns that indicate entry points
23
+ ENTRY_POINT_PATTERNS = {
24
+ # Main / CLI
25
+ "main": 10,
26
+ "run": 3,
27
+ "start": 3,
28
+ "execute": 3,
29
+ "cli": 3,
30
+ # API handlers (Express, FastAPI, Spring, etc.)
31
+ "handler": 5,
32
+ "handle": 4,
33
+ "controller": 5,
34
+ # HTTP methods
35
+ "get": 2,
36
+ "post": 2,
37
+ "put": 2,
38
+ "delete": 2,
39
+ "patch": 2,
40
+ # Test functions
41
+ "test": 4,
42
+ "it": 3,
43
+ "describe": 3,
44
+ "spec": 3,
45
+ # Lifecycle hooks
46
+ "ngOnInit": 5,
47
+ "componentDidMount": 5,
48
+ "useEffect": 2,
49
+ "onCreate": 5,
50
+ "onStart": 5,
51
+ # Scheduled tasks
52
+ "schedule": 4,
53
+ "cron": 4,
54
+ "job": 3,
55
+ "task": 3,
56
+ "worker": 3,
57
+ }
58
+
59
+ # Decorator patterns that indicate entry points
60
+ ENTRY_DECORATORS = {
61
+ "@app.route",
62
+ "@app.get",
63
+ "@app.post",
64
+ "@app.put",
65
+ "@app.delete",
66
+ "@router.get",
67
+ "@router.post",
68
+ "@api_view",
69
+ "@action",
70
+ "@GetMapping",
71
+ "@PostMapping",
72
+ "@PutMapping",
73
+ "@DeleteMapping",
74
+ "@RequestMapping",
75
+ "@Controller",
76
+ "@RestController",
77
+ "@Service",
78
+ "@Scheduled",
79
+ "@Test",
80
+ "@test",
81
+ "@pytest.fixture",
82
+ "@click.command",
83
+ "@celery.task",
84
+ }
85
+
86
+ # Class patterns that indicate entry point containers
87
+ ENTRY_CLASS_PATTERNS = {
88
+ "Controller",
89
+ "Handler",
90
+ "Resolver",
91
+ "Resource",
92
+ "Endpoint",
93
+ "View",
94
+ "Servlet",
95
+ "Component",
96
+ "Page",
97
+ "Service",
98
+ }
99
+
100
+
101
+ def score_entry_point(func: Dict[str, Any]) -> int:
102
+ """Score how likely a function is an entry point (0 = not, higher = more likely)."""
103
+ score = 0
104
+ name = func.get("name", "").lower()
105
+ decorators = func.get("decorators", []) or []
106
+ class_ctx = func.get("class_context", "") or ""
107
+
108
+ # Name-based scoring
109
+ for pattern, points in ENTRY_POINT_PATTERNS.items():
110
+ if pattern in name:
111
+ score += points
112
+ break
113
+
114
+ # Decorator-based scoring
115
+ for dec in decorators:
116
+ dec_str = str(dec).strip()
117
+ for entry_dec in ENTRY_DECORATORS:
118
+ if entry_dec.lower() in dec_str.lower():
119
+ score += 8
120
+ break
121
+
122
+ # Class context scoring
123
+ for cls_pattern in ENTRY_CLASS_PATTERNS:
124
+ if cls_pattern.lower() in class_ctx.lower():
125
+ score += 3
126
+ break
127
+
128
+ # Boost for exported/public functions (no leading underscore)
129
+ if name and not name.startswith("_"):
130
+ score += 1
131
+
132
+ # Boost for functions with no callers (leaf nodes in reverse graph)
133
+ # This is checked during flow detection, not here
134
+
135
+ return score
136
+
137
+
138
+ def detect_execution_flows(
139
+ parsed_results: List[Dict[str, Any]],
140
+ call_groups: Tuple,
141
+ max_flows: int = 300,
142
+ max_depth: int = 10,
143
+ repo_path: Optional[str] = None,
144
+ ) -> List[Dict[str, Any]]:
145
+ """Detect execution flows from entry points through call graph.
146
+
147
+ Args:
148
+ parsed_results: List of parsed file data (from Rust parser)
149
+ call_groups: 6-tuple of call edge lists (fn_fn, fn_cls, ...)
150
+ max_flows: Maximum number of flows to detect
151
+ max_depth: Maximum BFS depth per flow
152
+ repo_path: If given, normalize all paths to relative
153
+
154
+ Returns:
155
+ List of flow dicts: {
156
+ name: str, # entry point name
157
+ entry_file: str, # file path (relative if repo_path given)
158
+ entry_line: int, # line number
159
+ entry_class: str, # class context (if any)
160
+ steps: [{name, file, line, depth}], # ordered call chain
161
+ depth: int, # max depth reached
162
+ score: int, # entry point score
163
+ }
164
+ """
165
+ # Build call graph adjacency list: caller_key → [(callee_name, callee_path)]
166
+ adj: Dict[str, List[Tuple[str, str, int]]] = {} # key → [(name, path, line)]
167
+
168
+ for group in call_groups:
169
+ for edge in group:
170
+ caller_name = edge.get("caller_name", "")
171
+ caller_path = edge.get("caller_file_path", "")
172
+ called_name = edge.get("called_name", "")
173
+ called_path = edge.get("called_file_path", "")
174
+ line = edge.get("line_number", 0)
175
+
176
+ if not caller_name or not called_name:
177
+ continue
178
+
179
+ key = f"{caller_name}|{caller_path}"
180
+ if key not in adj:
181
+ adj[key] = []
182
+ adj[key].append((called_name, called_path, line))
183
+
184
+ # Build reverse graph to find functions with no callers
185
+ has_callers: Set[str] = set()
186
+ for group in call_groups:
187
+ for edge in group:
188
+ called_name = edge.get("called_name", "")
189
+ called_path = edge.get("called_file_path", "")
190
+ if called_name:
191
+ has_callers.add(f"{called_name}|{called_path}")
192
+
193
+ # Score all functions as potential entry points
194
+ candidates: List[Tuple[int, Dict[str, Any], str]] = []
195
+
196
+ for file_data in parsed_results:
197
+ if "error" in file_data:
198
+ continue
199
+ file_path = file_data.get("path", "")
200
+
201
+ for func in file_data.get("functions", []):
202
+ func_name = func.get("name", "")
203
+ func_key = f"{func_name}|{file_path}"
204
+
205
+ score = score_entry_point(func)
206
+
207
+ # Boost for functions with no callers (true entry points)
208
+ if func_key not in has_callers:
209
+ score += 2
210
+
211
+ if score >= 3: # minimum threshold
212
+ candidates.append((score, {**func, "path": file_path}, func_key))
213
+
214
+ # Sort by score descending, take top candidates
215
+ candidates.sort(key=lambda x: -x[0])
216
+ candidates = candidates[:max_flows * 2] # over-fetch, will filter
217
+
218
+ # Noise function names to skip during BFS (not interesting for flow tracing)
219
+ noise_names: Set[str] = {
220
+ # Java/generic
221
+ "ok", "of", "build", "builder", "toString", "hashCode", "equals",
222
+ "get", "set", "put", "add", "remove", "contains", "size", "isEmpty",
223
+ "valueOf", "values", "name", "ordinal", "compareTo",
224
+ "matcher", "matches", "group", "find", "pattern",
225
+ "append", "format", "trim", "split", "join", "replace",
226
+ "parseInt", "parseFloat", "parseLong", "parseDouble",
227
+ "asList", "singletonList", "emptyList", "emptyMap",
228
+ "HashMap<>", "ArrayList<>", "HashSet<>", "LinkedList<>",
229
+ "Optional", "ofNullable", "orElse", "orElseThrow", "isPresent",
230
+ "stream", "map", "filter", "collect", "forEach", "reduce", "flatMap",
231
+ "toList", "toSet", "toMap", "joining",
232
+ # Jackson / JSON
233
+ "asText", "asLong", "asInt", "asBoolean", "isMissingNode", "isArray",
234
+ "path", "readTree", "readValue", "writeValueAsString",
235
+ "jsonPath", "contentType", "content",
236
+ # Java time / lang
237
+ "currentTimeMillis", "nanoTime", "now", "toInstant", "atZone",
238
+ "getTime", "toLocalDate", "format",
239
+ # Java accessors (common getters)
240
+ "getId", "getName", "getStatus", "getType", "getValue",
241
+ "getCode", "getMessage", "getPath", "getClass",
242
+ "setId", "setName", "setStatus", "setType",
243
+ # BigDecimal / AtomicReference
244
+ "BigDecimal", "AtomicReference", "AtomicInteger", "AtomicLong",
245
+ "ZERO", "ONE", "TEN", "compareTo", "multiply", "divide",
246
+ # JS/TS generic
247
+ "then", "catch", "finally", "resolve", "reject",
248
+ "push", "pop", "shift", "slice", "splice", "concat",
249
+ "keys", "entries", "assign", "freeze", "create",
250
+ "log", "warn", "error", "info", "debug",
251
+ "JSON", "stringify", "parse",
252
+ "setTimeout", "setInterval", "clearTimeout", "clearInterval",
253
+ "Promise", "async", "await",
254
+ "require", "module", "exports",
255
+ "console", "document", "window",
256
+ # React
257
+ "useState", "useEffect", "useRef", "useCallback", "useMemo",
258
+ "useContext", "useReducer",
259
+ "preventDefault", "stopPropagation",
260
+ # Python
261
+ "print", "len", "range", "str", "int", "float", "bool", "list", "dict",
262
+ "super", "self", "cls",
263
+ }
264
+
265
+ # BFS from each entry point
266
+ flows: List[Dict[str, Any]] = []
267
+ seen_flows: Set[str] = set() # avoid duplicate flows
268
+
269
+ for score, func, func_key in candidates:
270
+ if len(flows) >= max_flows:
271
+ break
272
+
273
+ # BFS
274
+ steps: List[Dict[str, Any]] = []
275
+ visited: Set[str] = set()
276
+ queue: deque = deque()
277
+
278
+ # Start from entry point
279
+ entry_name = func.get("name", "")
280
+ entry_path = func.get("path", "")
281
+ entry_line = func.get("line_number", 0)
282
+ entry_class = func.get("class_context", "") or ""
283
+
284
+ queue.append((entry_name, entry_path, 0))
285
+ visited.add(func_key)
286
+
287
+ while queue and len(steps) < 50: # max 50 steps per flow
288
+ name, path, depth = queue.popleft()
289
+
290
+ if depth > max_depth:
291
+ continue
292
+
293
+ # Skip noise names from steps (keep entry point even if noisy)
294
+ if depth > 0 and name in noise_names:
295
+ continue
296
+
297
+ steps.append({
298
+ "name": name,
299
+ "file": path,
300
+ "line": 0,
301
+ "depth": depth,
302
+ })
303
+
304
+ # Follow outgoing calls (skip noise)
305
+ key = f"{name}|{path}"
306
+ for callee_name, callee_path, callee_line in adj.get(key, []):
307
+ if callee_name in noise_names:
308
+ continue
309
+ callee_key = f"{callee_name}|{callee_path}"
310
+ if callee_key not in visited:
311
+ visited.add(callee_key)
312
+ queue.append((callee_name, callee_path, depth + 1))
313
+
314
+ # Skip trivial flows (< 3 meaningful steps)
315
+ if len(steps) < 3:
316
+ continue
317
+
318
+ # Deduplicate by first 3 steps
319
+ flow_sig = "|".join(s["name"] for s in steps[:3])
320
+ if flow_sig in seen_flows:
321
+ continue
322
+ seen_flows.add(flow_sig)
323
+
324
+ flow_name = entry_name
325
+ if entry_class:
326
+ flow_name = f"{entry_class}.{entry_name}"
327
+
328
+ flows.append({
329
+ "name": flow_name,
330
+ "entry_file": entry_path,
331
+ "entry_line": entry_line,
332
+ "entry_class": entry_class,
333
+ "steps": steps,
334
+ "depth": max(s["depth"] for s in steps),
335
+ "step_count": len(steps),
336
+ "score": score,
337
+ })
338
+
339
+ # Normalize paths to relative if repo_path given
340
+ if repo_path:
341
+ repo_resolved = Path(repo_path).resolve()
342
+ for flow in flows:
343
+ try:
344
+ flow["entry_file"] = str(Path(flow["entry_file"]).relative_to(repo_resolved))
345
+ except (ValueError, TypeError):
346
+ pass
347
+ for step in flow.get("steps", []):
348
+ try:
349
+ step["file"] = str(Path(step["file"]).relative_to(repo_resolved))
350
+ except (ValueError, TypeError):
351
+ pass
352
+
353
+ flows.sort(key=lambda x: (-x["score"], -x["step_count"]))
354
+ logger.info("Detected %d execution flows from %d candidates", len(flows), len(candidates))
355
+ return flows[:max_flows]