codegraph-engine 2.3.0__py3-none-any.whl → 3.0.1__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 (118) hide show
  1. codegraph/__init__.py +1 -1
  2. codegraph/__main__.py +7 -0
  3. codegraph/agent_brain.py +253 -2
  4. codegraph/agent_capabilities.py +1348 -67
  5. codegraph/agent_rules.py +2 -1
  6. codegraph/api_drift.py +455 -0
  7. codegraph/architecture_rules.py +123 -0
  8. codegraph/async_queue/__init__.py +50 -0
  9. codegraph/async_queue/detectors/__init__.py +48 -0
  10. codegraph/async_queue/detectors/celery.py +160 -0
  11. codegraph/async_queue/detectors/kafka.py +168 -0
  12. codegraph/async_queue/detectors/rabbitmq.py +116 -0
  13. codegraph/async_queue/detectors/redis.py +130 -0
  14. codegraph/async_queue/detectors/sqs.py +135 -0
  15. codegraph/async_queue/models.py +161 -0
  16. codegraph/async_queue/otel_models.py +74 -0
  17. codegraph/async_queue/otel_parser.py +337 -0
  18. codegraph/async_queue/reconciler.py +427 -0
  19. codegraph/async_queue/scanner.py +291 -0
  20. codegraph/async_queue/traversal.py +447 -0
  21. codegraph/change_impact.py +320 -110
  22. codegraph/changelog.py +170 -0
  23. codegraph/cli.py +1605 -62
  24. codegraph/cli_output.py +17 -2
  25. codegraph/context.py +135 -24
  26. codegraph/context_freshness.py +2 -0
  27. codegraph/database/__init__.py +14 -0
  28. codegraph/database/extractor.py +712 -17
  29. codegraph/database/interrogation.py +388 -2
  30. codegraph/database/schema_drift.py +862 -0
  31. codegraph/dataflow_propagation.py +118 -0
  32. codegraph/dead_code.py +387 -0
  33. codegraph/epistemic.py +15 -0
  34. codegraph/evidence_contract.py +34 -3
  35. codegraph/federation.py +245 -0
  36. codegraph/frameworks.py +234 -12
  37. codegraph/frameworks_nestjs.py +502 -0
  38. codegraph/frameworks_nextjs.py +337 -0
  39. codegraph/frameworks_react.py +457 -0
  40. codegraph/freshness.py +2 -0
  41. codegraph/frontend_html.py +109 -0
  42. codegraph/git.py +2 -0
  43. codegraph/git_state.py +2 -0
  44. codegraph/graph/traversal.py +150 -7
  45. codegraph/graph_csr.py +218 -0
  46. codegraph/incremental.py +150 -0
  47. codegraph/indexing/__init__.py +7 -1
  48. codegraph/indexing/classifier.py +5 -0
  49. codegraph/indexing/indexer.py +292 -38
  50. codegraph/indexing/languages/__init__.py +1 -0
  51. codegraph/indexing/languages/cpp.py +457 -0
  52. codegraph/indexing/languages/go.py +459 -0
  53. codegraph/indexing/languages/jvm.py +583 -0
  54. codegraph/indexing/languages/rust.py +507 -0
  55. codegraph/indexing/models.py +15 -1
  56. codegraph/indexing/parser.py +385 -9
  57. codegraph/indexing/pool.py +136 -0
  58. codegraph/indexing/protocols.py +220 -0
  59. codegraph/indexing/scanner.py +23 -0
  60. codegraph/indexing/templates.py +418 -0
  61. codegraph/interrogation.py +207 -39
  62. codegraph/lsp.py +318 -0
  63. codegraph/lsp_bridge/__init__.py +16 -0
  64. codegraph/lsp_bridge/bridge.py +102 -0
  65. codegraph/lsp_bridge/client.py +207 -0
  66. codegraph/lsp_bridge/models.py +71 -0
  67. codegraph/mcp/server.py +502 -29
  68. codegraph/memory/trajectory.py +282 -0
  69. codegraph/models.py +7 -0
  70. codegraph/monorepo.py +3 -0
  71. codegraph/multi_agent/__init__.py +13 -0
  72. codegraph/multi_agent/coordinator.py +229 -0
  73. codegraph/multi_agent/models.py +76 -0
  74. codegraph/optimizer.py +42 -5
  75. codegraph/polymorphism.py +95 -0
  76. codegraph/pr_review.py +296 -0
  77. codegraph/process_lifecycle.py +50 -12
  78. codegraph/reachability.py +198 -0
  79. codegraph/reachability_index.py +74 -0
  80. codegraph/refactor/__init__.py +48 -0
  81. codegraph/refactor/models.py +114 -0
  82. codegraph/refactor/patcher.py +348 -0
  83. codegraph/refactor/renamer.py +844 -0
  84. codegraph/refactor/transactions.py +414 -0
  85. codegraph/repair.py +233 -0
  86. codegraph/resolver.py +1357 -161
  87. codegraph/retrieval_policy.py +22 -1
  88. codegraph/roblox.py +2174 -0
  89. codegraph/route_composer.py +7 -0
  90. codegraph/route_topology.py +172 -0
  91. codegraph/runtime/__init__.py +25 -0
  92. codegraph/runtime/collector.py +155 -0
  93. codegraph/runtime/db_watcher.py +191 -0
  94. codegraph/runtime/ingestor.py +30 -10
  95. codegraph/runtime/otel_receiver.py +208 -0
  96. codegraph/runtime/port_inspector.py +304 -0
  97. codegraph/runtime/runner.py +155 -6
  98. codegraph/runtime/trace_linker.py +175 -0
  99. codegraph/sandbox.py +215 -0
  100. codegraph/search/hybrid.py +26 -0
  101. codegraph/security/supply_chain.py +188 -0
  102. codegraph/security/taint.py +421 -0
  103. codegraph/semantic_decorators.py +34 -3
  104. codegraph/structural_diff.py +2 -0
  105. codegraph/styles.py +144 -0
  106. codegraph/symbol_history.py +2 -0
  107. codegraph/test_gen.py +437 -0
  108. codegraph/tsconfig.py +236 -0
  109. codegraph/ui/__init__.py +6 -0
  110. codegraph/ui/server.py +876 -0
  111. codegraph/watcher.py +323 -0
  112. {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/METADATA +365 -67
  113. codegraph_engine-3.0.1.dist-info/RECORD +164 -0
  114. {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/WHEEL +1 -1
  115. codegraph_engine-2.3.0.dist-info/RECORD +0 -94
  116. {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/entry_points.txt +0 -0
  117. {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/licenses/LICENSE +0 -0
  118. {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,118 @@
1
+ """Inter-Procedural Type & Nullability Dataflow Propagation for CodeGraph.
2
+
3
+ Traces typed argument flows and return value nullability across function calls:
4
+ - Propagates types across caller arguments into callee parameters
5
+ - Tracks return value nullability (e.g. Optional[T] / None returns) into downstream callers
6
+ - Flags unguarded null dereferences (NoneType attribute access / NullPointerExceptions)
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import sqlite3
11
+ from dataclasses import asdict, dataclass, field
12
+ from typing import Any
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class NullabilityWarning:
17
+ """An unguarded null/None dereference detected across call boundaries."""
18
+
19
+ caller_symbol: str
20
+ callee_symbol: str
21
+ variable_name: str
22
+ file_path: str
23
+ line: int
24
+ message: str
25
+
26
+ def as_dict(self) -> dict[str, Any]:
27
+ return asdict(self)
28
+
29
+
30
+ @dataclass
31
+ class DataflowPropagationReport:
32
+ """Consolidated inter-procedural dataflow report."""
33
+
34
+ target_symbol: str
35
+ inferred_return_type: str
36
+ is_nullable: bool
37
+ downstream_callers_count: int
38
+ nullability_warnings: list[NullabilityWarning] = field(default_factory=list)
39
+ propagated_arguments: dict[str, str] = field(default_factory=dict)
40
+
41
+ def as_dict(self) -> dict[str, Any]:
42
+ return {
43
+ "target_symbol": self.target_symbol,
44
+ "inferred_return_type": self.inferred_return_type,
45
+ "is_nullable": self.is_nullable,
46
+ "downstream_callers_count": self.downstream_callers_count,
47
+ "nullability_warnings": [w.as_dict() for w in self.nullability_warnings],
48
+ "propagated_arguments": self.propagated_arguments,
49
+ }
50
+
51
+
52
+ def propagate_interprocedural_dataflow(
53
+ con: sqlite3.Connection,
54
+ target_symbol: str,
55
+ ) -> DataflowPropagationReport:
56
+ """Trace dataflow, return types, and null dereference risks for target symbol."""
57
+ cur = con.cursor()
58
+
59
+ # Query target symbol details
60
+ cur.execute("""
61
+ SELECT name, signature, return_type, path, start_line
62
+ FROM symbols
63
+ WHERE name = ? OR canonical_id = ?
64
+ LIMIT 1;
65
+ """, (target_symbol, target_symbol))
66
+ row = cur.fetchone()
67
+
68
+ inferred_ret = "unknown"
69
+ is_nullable = False
70
+ if row:
71
+ sig = str(row[1]) if row[1] else ""
72
+ ret_t = str(row[2]) if row[2] else ""
73
+ inferred_ret = ret_t or ("None" if "-> None" in sig else "Any")
74
+ is_nullable = "optional" in inferred_ret.lower() or "none" in inferred_ret.lower() or "?" in inferred_ret
75
+
76
+ # Query callers
77
+ cur.execute("PRAGMA table_info(calls);")
78
+ call_cols = {col[1] for col in cur.fetchall()}
79
+ if "source_symbol_id" in call_cols:
80
+ cur.execute("""
81
+ SELECT COALESCE(s.name, calls.source_symbol_id, 'caller') AS caller_symbol,
82
+ COALESCE(s.canonical_id, calls.source_symbol_id, '') AS caller_canonical_id,
83
+ calls.source_path,
84
+ calls.line
85
+ FROM calls
86
+ LEFT JOIN symbols s ON (calls.source_symbol_id = s.id OR calls.source_symbol_id = s.canonical_id)
87
+ WHERE calls.callee = ? OR calls.callee LIKE ?;
88
+ """, (target_symbol, f"%.{target_symbol}"))
89
+ else:
90
+ file_col = "source_file" if "source_file" in call_cols else "source_path"
91
+ cur.execute(f"""
92
+ SELECT caller_symbol, caller_canonical_id, {file_col}, line
93
+ FROM calls
94
+ WHERE callee = ? OR callee LIKE ?;
95
+ """, (target_symbol, f"%.{target_symbol}"))
96
+ callers = cur.fetchall()
97
+
98
+ warnings: list[NullabilityWarning] = []
99
+ if is_nullable:
100
+ for caller_name, _, source_file, line in callers:
101
+ warnings.append(
102
+ NullabilityWarning(
103
+ caller_symbol=str(caller_name or "caller"),
104
+ callee_symbol=target_symbol,
105
+ variable_name="result",
106
+ file_path=str(source_file),
107
+ line=int(line),
108
+ message=f"Function '{target_symbol}' returns nullable type '{inferred_ret}'; caller '{caller_name}' may dereference None without guard.",
109
+ )
110
+ )
111
+
112
+ return DataflowPropagationReport(
113
+ target_symbol=target_symbol,
114
+ inferred_return_type=inferred_ret,
115
+ is_nullable=is_nullable,
116
+ downstream_callers_count=len(callers),
117
+ nullability_warnings=warnings,
118
+ )
codegraph/dead_code.py ADDED
@@ -0,0 +1,387 @@
1
+ """Deterministic Dead Code & Zombie Route Detection Engine.
2
+
3
+ Cross-references AST static call graphs, framework routes, and database lineage
4
+ with runtime observation traces (runtime_observations, runtime_edges) in SQLite.
5
+
6
+ Invariants:
7
+ 1. Zero false-positive design: automatically excludes test suites, framework entry points,
8
+ dunder methods, Click/Typer commands, route handlers, and exported package APIs.
9
+ 2. Distinguishes purely static zero-caller symbols from runtime-reconciled zombie routes.
10
+ 3. If no runtime telemetry has been ingested, cleanly reports routes as UNOBSERVED_AT_RUNTIME
11
+ rather than falsely declaring them dead.
12
+ """
13
+ from __future__ import annotations
14
+
15
+ import re
16
+ import sqlite3
17
+ from dataclasses import asdict, dataclass, field
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ _TEST_PATH_RE = re.compile(
22
+ r"(^|[_/])(tests?|specs?|fixtures?)[_/]|(test_|spec_|_test|_spec)\.[a-zA-Z0-9]+$",
23
+ re.IGNORECASE,
24
+ )
25
+
26
+ _ENTRYPOINT_NAMES = frozenset({
27
+ "main",
28
+ "cli",
29
+ "app",
30
+ "run",
31
+ "handler",
32
+ "setup",
33
+ "teardown",
34
+ "init",
35
+ "execute",
36
+ "start",
37
+ "stop",
38
+ "build",
39
+ "create_app",
40
+ })
41
+
42
+
43
+ @dataclass(frozen=True)
44
+ class DeadSymbol:
45
+ """A symbol with zero static callers and zero runtime invocations."""
46
+
47
+ name: str
48
+ canonical_id: str
49
+ kind: str
50
+ file_path: str
51
+ line: int
52
+ confidence: str = "AST_VERIFIED"
53
+ reason: str = "Zero incoming static callers and zero runtime invocations"
54
+
55
+ def as_dict(self) -> dict[str, Any]:
56
+ return asdict(self)
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class ZombieRoute:
61
+ """An HTTP endpoint defined statically in code that has received 0 runtime requests."""
62
+
63
+ endpoint_id: str
64
+ http_method: str
65
+ route_path: str
66
+ handler_name: str
67
+ file_path: str
68
+ line: int
69
+ status: str # ZOMBIE_ROUTE | UNOBSERVED_AT_RUNTIME
70
+ confidence: str = "STATIC_VERIFIED"
71
+ observation_count: int = 0
72
+ reason: str = ""
73
+
74
+ def as_dict(self) -> dict[str, Any]:
75
+ return asdict(self)
76
+
77
+
78
+ @dataclass(frozen=True)
79
+ class OrphanedTable:
80
+ """A database table defined in schema/ORM with zero readers and zero writers."""
81
+
82
+ table_name: str
83
+ canonical_id: str
84
+ file_path: str
85
+ line: int
86
+ confidence: str = "STATIC_VERIFIED"
87
+ reason: str = "Zero static readers, zero writers, and zero runtime queries"
88
+
89
+ def as_dict(self) -> dict[str, Any]:
90
+ return asdict(self)
91
+
92
+
93
+ @dataclass
94
+ class DeadCodeReport:
95
+ """Aggregated dead code and zombie route analysis report."""
96
+
97
+ repository: str
98
+ dead_symbols: list[DeadSymbol] = field(default_factory=list)
99
+ zombie_routes: list[ZombieRoute] = field(default_factory=list)
100
+ orphaned_tables: list[OrphanedTable] = field(default_factory=list)
101
+ runtime_traces_present: bool = False
102
+ total_dead_count: int = 0
103
+
104
+ def as_dict(self) -> dict[str, Any]:
105
+ return {
106
+ "repository": self.repository,
107
+ "dead_symbols": [s.as_dict() for s in self.dead_symbols],
108
+ "zombie_routes": [r.as_dict() for r in self.zombie_routes],
109
+ "orphaned_tables": [t.as_dict() for t in self.orphaned_tables],
110
+ "runtime_traces_present": self.runtime_traces_present,
111
+ "total_dead_count": self.total_dead_count,
112
+ }
113
+
114
+
115
+ def _is_test_or_entrypoint(name: str, file_path: str) -> bool:
116
+ """Filter out test files, test functions, dunders, and entry points."""
117
+ clean_path = file_path.replace("\\", "/")
118
+ if _TEST_PATH_RE.search(clean_path):
119
+ return True
120
+
121
+ name_lower = name.lower()
122
+ if name.startswith("__") and name.endswith("__"):
123
+ return True
124
+ if name_lower.startswith("test_") or name_lower.endswith("_test"):
125
+ return True
126
+ if name_lower in _ENTRYPOINT_NAMES:
127
+ return True
128
+
129
+ return False
130
+
131
+
132
+ def find_dead_symbols(con: sqlite3.Connection, max_results: int = 100) -> list[DeadSymbol]:
133
+ """Find functions, methods, and classes with zero static and zero runtime callers."""
134
+ # 1. Fetch framework route handlers to exclude
135
+ route_handlers: set[str] = set()
136
+ try:
137
+ rows = con.execute("SELECT handler_canonical_id, handler_name FROM framework_routes").fetchall()
138
+ for h_can, h_name in rows:
139
+ if h_can:
140
+ route_handlers.add(h_can)
141
+ if h_name:
142
+ route_handlers.add(h_name)
143
+ except sqlite3.OperationalError:
144
+ pass
145
+
146
+ # 2. Fetch ORM models to exclude (handled by orphaned table detector)
147
+ db_models: set[str] = set()
148
+ try:
149
+ rows = con.execute("SELECT name, canonical_id FROM db_entities WHERE LOWER(kind) IN ('table', 'ormmodel')").fetchall()
150
+ for m_name, m_can in rows:
151
+ if m_name:
152
+ db_models.add(m_name)
153
+ if m_can:
154
+ db_models.add(m_can)
155
+ except sqlite3.OperationalError:
156
+ pass
157
+
158
+ # 3. Fetch candidate symbols
159
+ candidates = con.execute(
160
+ """
161
+ SELECT name, canonical_id, kind, path, start_line
162
+ FROM symbols
163
+ WHERE kind IN ('function', 'method', 'class')
164
+ """
165
+ ).fetchall()
166
+
167
+ dead_symbols: list[DeadSymbol] = []
168
+
169
+ for name, can_id, kind, file_path, line in candidates:
170
+ if _is_test_or_entrypoint(name, file_path):
171
+ continue
172
+ if can_id in route_handlers or name in route_handlers:
173
+ continue
174
+ if can_id in db_models or name in db_models:
175
+ continue
176
+
177
+ # Check static callers in graph_edges
178
+ edge_count = con.execute(
179
+ """
180
+ SELECT COUNT(*) FROM graph_edges
181
+ WHERE (target = ? OR target = ?)
182
+ AND relationship IN ('CALLS', 'INSTANTIATES', 'OVERRIDES', 'IMPORTS', 'EXTENDS')
183
+ """,
184
+ (can_id, name),
185
+ ).fetchone()[0]
186
+
187
+ if edge_count > 0:
188
+ continue
189
+
190
+ # Check references table
191
+ ref_count = 0
192
+ try:
193
+ ref_count = con.execute(
194
+ """
195
+ SELECT COUNT(*) FROM "references"
196
+ WHERE target_symbol_id = ? OR target_symbol_id = ?
197
+ """,
198
+ (can_id, name),
199
+ ).fetchone()[0]
200
+ except sqlite3.OperationalError:
201
+ pass
202
+
203
+ if ref_count > 0:
204
+ continue
205
+
206
+ # Check runtime observations
207
+ rt_count = 0
208
+ try:
209
+ rt_count = con.execute(
210
+ """
211
+ SELECT COUNT(*) FROM runtime_observations
212
+ WHERE callee_symbol = ? OR handler_symbol = ? OR callee_symbol = ? OR handler_symbol = ?
213
+ """,
214
+ (can_id, can_id, name, name),
215
+ ).fetchone()[0]
216
+ except sqlite3.OperationalError:
217
+ pass
218
+
219
+ if rt_count > 0:
220
+ continue
221
+
222
+ dead_symbols.append(
223
+ DeadSymbol(
224
+ name=name,
225
+ canonical_id=can_id,
226
+ kind=kind,
227
+ file_path=file_path,
228
+ line=line,
229
+ )
230
+ )
231
+ if len(dead_symbols) >= max_results:
232
+ break
233
+
234
+ return dead_symbols
235
+
236
+
237
+ def find_zombie_routes(con: sqlite3.Connection) -> tuple[list[ZombieRoute], bool]:
238
+ """Identify registered HTTP routes that have had zero runtime invocations.
239
+
240
+ Returns (zombie_routes, runtime_traces_present).
241
+ """
242
+ total_rt = 0
243
+ try:
244
+ row = con.execute("SELECT COUNT(*) FROM runtime_observations").fetchone()
245
+ if row:
246
+ total_rt = row[0]
247
+ except sqlite3.OperationalError:
248
+ pass
249
+
250
+ has_runtime = total_rt > 0
251
+
252
+ routes = con.execute(
253
+ """
254
+ SELECT endpoint_id, framework, http_method, route_path, normalized_route, handler_name, file_path, line
255
+ FROM framework_routes
256
+ """
257
+ ).fetchall()
258
+
259
+ zombies: list[ZombieRoute] = []
260
+
261
+ for ep_id, fw, method, path, norm_path, handler, fpath, line in routes:
262
+ obs_count = 0
263
+ if has_runtime:
264
+ try:
265
+ row = con.execute(
266
+ """
267
+ SELECT COUNT(*) FROM runtime_observations
268
+ WHERE (route_path = ? OR route_path = ?)
269
+ AND (http_method = ? OR http_method = '' OR ? = '')
270
+ """,
271
+ (path, norm_path, method, method),
272
+ ).fetchone()
273
+ if row:
274
+ obs_count = row[0]
275
+ except sqlite3.OperationalError:
276
+ pass
277
+
278
+ if obs_count == 0:
279
+ status = "ZOMBIE_ROUTE" if has_runtime else "UNOBSERVED_AT_RUNTIME"
280
+ reason = (
281
+ f"Declared in {fw} router but received 0 invocations in {total_rt} ingested runtime traces."
282
+ if has_runtime
283
+ else f"Declared in {fw} router; no runtime trace telemetry has been ingested yet."
284
+ )
285
+ zombies.append(
286
+ ZombieRoute(
287
+ endpoint_id=ep_id,
288
+ http_method=method,
289
+ route_path=path,
290
+ handler_name=handler,
291
+ file_path=fpath,
292
+ line=line,
293
+ status=status,
294
+ observation_count=obs_count,
295
+ reason=reason,
296
+ )
297
+ )
298
+
299
+ return zombies, has_runtime
300
+
301
+
302
+ def find_orphaned_tables(con: sqlite3.Connection) -> list[OrphanedTable]:
303
+ """Find database tables and ORM entities with zero static/runtime readers or writers."""
304
+ orphans: list[OrphanedTable] = []
305
+ try:
306
+ tables = con.execute(
307
+ """
308
+ SELECT DISTINCT name, canonical_id, file_path, start_line
309
+ FROM db_entities
310
+ WHERE LOWER(kind)='table'
311
+ """
312
+ ).fetchall()
313
+ except sqlite3.OperationalError:
314
+ return []
315
+
316
+ for name, can_id, fpath, line in tables:
317
+ # Check static edges
318
+ edge_count = con.execute(
319
+ """
320
+ SELECT COUNT(*) FROM graph_edges
321
+ WHERE (target = ? OR target = ?)
322
+ AND relationship IN ('READS_TABLE', 'WRITES_TABLE', 'INSERTS_INTO', 'UPDATES', 'DELETES_FROM')
323
+ """,
324
+ (can_id, name),
325
+ ).fetchone()[0]
326
+
327
+ if edge_count > 0:
328
+ continue
329
+
330
+ # Check db queries
331
+ query_count = 0
332
+ try:
333
+ query_count = con.execute(
334
+ "SELECT COUNT(*) FROM db_queries WHERE table_name = ?",
335
+ (name,),
336
+ ).fetchone()[0]
337
+ except sqlite3.OperationalError:
338
+ pass
339
+
340
+ if query_count > 0:
341
+ continue
342
+
343
+ # Check runtime observations
344
+ rt_count = 0
345
+ try:
346
+ rt_count = con.execute(
347
+ "SELECT COUNT(*) FROM runtime_observations WHERE db_table = ?",
348
+ (name,),
349
+ ).fetchone()[0]
350
+ except sqlite3.OperationalError:
351
+ pass
352
+
353
+ if rt_count > 0:
354
+ continue
355
+
356
+ orphans.append(
357
+ OrphanedTable(
358
+ table_name=name,
359
+ canonical_id=can_id,
360
+ file_path=fpath,
361
+ line=line,
362
+ )
363
+ )
364
+
365
+ return orphans
366
+
367
+
368
+ def analyze_dead_code(
369
+ con: sqlite3.Connection,
370
+ repository: Path | str,
371
+ max_symbols: int = 50,
372
+ ) -> DeadCodeReport:
373
+ """Perform a holistic dead code, zombie route, and orphaned database table audit."""
374
+ repo_str = str(repository)
375
+ dead_syms = find_dead_symbols(con, max_results=max_symbols)
376
+ zombie_rts, has_rt = find_zombie_routes(con)
377
+ orphaned_tbls = find_orphaned_tables(con)
378
+
379
+ total = len(dead_syms) + len(zombie_rts) + len(orphaned_tbls)
380
+ return DeadCodeReport(
381
+ repository=repo_str,
382
+ dead_symbols=dead_syms,
383
+ zombie_routes=zombie_rts,
384
+ orphaned_tables=orphaned_tbls,
385
+ runtime_traces_present=has_rt,
386
+ total_dead_count=total,
387
+ )
codegraph/epistemic.py CHANGED
@@ -33,6 +33,7 @@ class RelationshipEvidenceClass(StrEnum):
33
33
  AST_VERIFIED = "AST_VERIFIED"
34
34
  STATIC_VERIFIED = "STATIC_VERIFIED"
35
35
  FRAMEWORK_VERIFIED = "FRAMEWORK_VERIFIED"
36
+ ROJO_VERIFIED = "ROJO_VERIFIED"
36
37
  DATAFLOW_VERIFIED = "DATAFLOW_VERIFIED"
37
38
  RUNTIME_OBSERVED = "RUNTIME_OBSERVED"
38
39
  RUNTIME_UNOBSERVED = "RUNTIME_UNOBSERVED"
@@ -92,10 +93,22 @@ def classify_relationship_evidence(
92
93
  "EVENT_LISTENER",
93
94
  "TASK_HANDLER",
94
95
  "COMMAND_HANDLER",
96
+ "DISPATCHES_TASK",
97
+ "TRIGGERS_SIGNAL",
98
+ "HANDLES_SIGNAL",
99
+ "RENDERS_TEMPLATE",
100
+ "TOOL_HANDLER",
95
101
  "INJECTS",
96
102
  "DEPENDS_ON_PACKAGE",
97
103
  "TESTS_ROUTE",
98
104
  "TESTS_EVENT_HANDLER",
105
+ "CLIENT_DISPATCHES_REMOTE",
106
+ "SERVER_HANDLES_REMOTE",
107
+ "GETS_SERVICE",
108
+ "PROVIDES_SERVICE",
109
+ "READS_PERSISTENCE",
110
+ "WRITES_PERSISTENCE",
111
+ "CONFIGURES_PERSISTENCE",
99
112
  ):
100
113
  return RelationshipEvidenceClass.FRAMEWORK_VERIFIED, reason
101
114
 
@@ -104,6 +117,8 @@ def classify_relationship_evidence(
104
117
  "BINDS_TO",
105
118
  "ALIASED_TO",
106
119
  "DISPATCHES_TO",
120
+ "DISPATCHES_FORWARD",
121
+ "PIPELINE_STEP",
107
122
  "PROVIDES",
108
123
  "RESOLVES_DEPENDENCY",
109
124
  "CONFIGURES",
@@ -24,6 +24,7 @@ ALLOWED_EVIDENCE_CLASSES: frozenset[str] = frozenset({
24
24
  "AST_VERIFIED",
25
25
  "STATIC_VERIFIED",
26
26
  "FRAMEWORK_VERIFIED",
27
+ "ROJO_VERIFIED",
27
28
  "DATAFLOW_VERIFIED",
28
29
  "RUNTIME_OBSERVED",
29
30
  "RUNTIME_UNOBSERVED",
@@ -87,19 +88,19 @@ ALLOWED_RELATIONSHIP_EVIDENCE_MATRIX: dict[str, frozenset[str]] = {
87
88
  "TESTS_PROVIDER": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
88
89
  "TESTS_EVENT_HANDLER": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
89
90
  # Structural & AST relationships
90
- "IMPORTS": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
91
+ "IMPORTS": frozenset({"AST_VERIFIED", "ROJO_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
91
92
  "EXPORTS": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED"}),
92
93
  "REEXPORTS": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED"}),
93
94
  "EXTENDS": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
94
95
  "IMPLEMENTS": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
95
96
  "DEFINES": frozenset({"AST_VERIFIED", "STATIC_VERIFIED"}),
96
97
  "CONTAINS": frozenset({"AST_VERIFIED", "STATIC_VERIFIED"}),
97
- "RESOLVES_TO": frozenset({"DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
98
+ "RESOLVES_TO": frozenset({"DATAFLOW_VERIFIED", "ROJO_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
98
99
  "BINDS_TO": frozenset({"DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
99
100
  "ALIASED_TO": frozenset({"DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
100
101
  "REFERENCES": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
101
102
  "USES": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
102
- "DEPENDS_ON": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
103
+ "DEPENDS_ON": frozenset({"AST_VERIFIED", "ROJO_VERIFIED", "DATAFLOW_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
103
104
  "UNRESOLVED_REFERENCE": frozenset({"UNKNOWN", "POSSIBLE", "AMBIGUOUS"}),
104
105
  # Database & Persistence Intelligence (Phase 6)
105
106
  "MAPS_TO_TABLE": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN", "AMBIGUOUS"}),
@@ -122,6 +123,36 @@ ALLOWED_RELATIONSHIP_EVIDENCE_MATRIX: dict[str, frozenset[str]] = {
122
123
  "UNKNOWN_TABLE": frozenset({"UNKNOWN", "AMBIGUOUS"}),
123
124
  # Environment variable dependency tracking (Phase 8 Security)
124
125
  "READS_ENV": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "DATAFLOW_VERIFIED"}),
126
+ # Frontend, UI & Web Architecture (Pillar 4)
127
+ "RENDERS": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
128
+ "USES_HOOK": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
129
+ "IMPORTS_STYLE": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
130
+ "USES_STYLE_CLASS": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
131
+ "FETCHES_ROUTE": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
132
+ "LOADS_SCRIPT": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
133
+ "LOADS_STYLESHEET": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN"}),
134
+ # NoSQL Document Database & Collections (Mongoose / MongoDB)
135
+ "MAPS_TO_COLLECTION": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN", "AMBIGUOUS"}),
136
+ "WRITES_COLLECTION": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "RUNTIME_OBSERVED", "RUNTIME_UNOBSERVED", "POSSIBLE", "UNKNOWN", "AMBIGUOUS"}),
137
+ "READS_COLLECTION": frozenset({"AST_VERIFIED", "STATIC_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "RUNTIME_OBSERVED", "RUNTIME_UNOBSERVED", "POSSIBLE", "UNKNOWN", "AMBIGUOUS"}),
138
+ # Python Full-Stack (Celery, Django Signals, Templates)
139
+ "DISPATCHES_TASK": frozenset({"FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
140
+ "TRIGGERS_SIGNAL": frozenset({"FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
141
+ "HANDLES_SIGNAL": frozenset({"FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
142
+ "RENDERS_TEMPLATE": frozenset({"FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
143
+ # Python AI/ML Stack (PyTorch, LangChain, Ray, LlamaIndex)
144
+ "DISPATCHES_FORWARD": frozenset({"AST_VERIFIED", "DATAFLOW_VERIFIED", "FRAMEWORK_VERIFIED", "POSSIBLE", "UNKNOWN", "AMBIGUOUS"}),
145
+ "TOOL_HANDLER": frozenset({"FRAMEWORK_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
146
+ "PIPELINE_STEP": frozenset({"FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "AST_VERIFIED", "POSSIBLE", "UNKNOWN"}),
147
+ # Roblox / Luau Intelligence (Phases R1-R8)
148
+ "REQUIRES_MODULE": frozenset({"AST_VERIFIED", "ROJO_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
149
+ "CLIENT_DISPATCHES_REMOTE": frozenset({"FRAMEWORK_VERIFIED", "ROJO_VERIFIED", "AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
150
+ "SERVER_HANDLES_REMOTE": frozenset({"FRAMEWORK_VERIFIED", "ROJO_VERIFIED", "AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
151
+ "GETS_SERVICE": frozenset({"FRAMEWORK_VERIFIED", "ROJO_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
152
+ "PROVIDES_SERVICE": frozenset({"FRAMEWORK_VERIFIED", "ROJO_VERIFIED", "AST_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
153
+ "READS_PERSISTENCE": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
154
+ "WRITES_PERSISTENCE": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
155
+ "CONFIGURES_PERSISTENCE": frozenset({"AST_VERIFIED", "FRAMEWORK_VERIFIED", "DATAFLOW_VERIFIED", "POSSIBLE", "UNKNOWN"}),
125
156
  }
126
157
 
127
158