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
codegraph/cli_output.py CHANGED
@@ -17,21 +17,36 @@ from typing import Any, TextIO
17
17
 
18
18
  import typer
19
19
 
20
- _PROBE_GLYPHS = "✓✗⚠↻•→↓─—–"
20
+ _PROBE_GLYPHS = "✓✗⚠↻•→↓─—–├──└──│📄📞🌐🧪💾⚠️✅❌"
21
21
 
22
22
  # Ordered replacements so multi-char patterns (e.g. "(•)") are replaced before single chars ("•")
23
23
  _UNICODE_TO_ASCII_MAP: tuple[tuple[str, str], ...] = (
24
24
  ("(•)", "(*)"),
25
+ ("├── ", "|-- "),
26
+ ("└── ", "\\-- "),
27
+ ("├──", "|--"),
28
+ ("└──", "\\--"),
29
+ ("├─", "|-"),
30
+ ("└─", "\\-"),
31
+ ("│", "|"),
32
+ ("─", "-"),
25
33
  ("✓", "[OK]"),
26
34
  ("✗", "[ERROR]"),
27
35
  ("⚠", "[WARN]"),
28
36
  ("↻", "[REPAIRED]"),
37
+ ("⚠️", "[WARN]"),
38
+ ("✅", "[OK]"),
39
+ ("❌", "[ERROR]"),
40
+ ("📄", "[FILE]"),
41
+ ("📞", "[CALLER]"),
42
+ ("🌐", "[ROUTE]"),
43
+ ("🧪", "[TEST]"),
44
+ ("💾", "[DB]"),
29
45
  ("•", "*"),
30
46
  ("→", "->"),
31
47
  ("↓", "v"),
32
48
  ("—", "--"),
33
49
  ("–", "-"),
34
- ("─", "-"),
35
50
  )
36
51
 
37
52
 
codegraph/context.py CHANGED
@@ -217,6 +217,46 @@ class ContextPacket(BaseModel):
217
217
  def to_dict(self) -> dict[str, object]:
218
218
  return self.model_dump()
219
219
 
220
+ def format_human(self) -> str:
221
+ """Format a clean, concise, token-efficient human/agent context summary."""
222
+ lines = [
223
+ f"# Context for Task: {self.task}",
224
+ f"**Intent**: {self.intent or 'UNDERSTAND'} | **Freshness**: {self.freshness} | **Selected Tokens**: ~{self.selected_tokens}",
225
+ "",
226
+ ]
227
+ if self.symbols:
228
+ lines.append("## Key Symbols")
229
+ for s in self.symbols[:8]:
230
+ loc = f"{s.file}:{s.start_line}-{s.end_line}" if s.start_line else s.file
231
+ lines.append(f"- **{s.symbol}** (`{s.kind}`) at `{loc}`")
232
+ lines.append("")
233
+
234
+ if self.evidence:
235
+ lines.append("## Targeted Code Evidence")
236
+ for ev in self.evidence[:5]:
237
+ lines.append(f"### {ev.file}:{ev.start_line}-{ev.end_line} ({ev.symbol or 'code'})")
238
+ lines.append("```")
239
+ lines.append(ev.snippet.strip())
240
+ lines.append("```")
241
+ lines.append("")
242
+
243
+ if self.relationships:
244
+ lines.append("## Verified Relationships")
245
+ for r in self.relationships[:8]:
246
+ lines.append(f"- `{r.source}` **{r.relationship}** `{r.target}` [{r.confidence}]")
247
+ lines.append("")
248
+
249
+ if self.routes:
250
+ lines.append("## Relevant Routes")
251
+ for rt in self.routes[:5]:
252
+ method = rt.get("method") or rt.get("http_method") or "ROUTE"
253
+ path = rt.get("path") or rt.get("route_path") or ""
254
+ handler = rt.get("handler") or rt.get("handler_name") or ""
255
+ lines.append(f"- `{method} {path}` -> `{handler}`")
256
+ lines.append("")
257
+
258
+ return "\n".join(lines).strip()
259
+
220
260
 
221
261
  # ---------------------------------------------------------------------------
222
262
  # Token estimation helper
@@ -301,7 +341,7 @@ def get_context(
301
341
  task: str | TaskSpec | dict[str, Any] = "",
302
342
  intent: Intent | str | None = None,
303
343
  max_tokens: int = 20_000,
304
- top_k: int = 15,
344
+ top_k: int = 25,
305
345
  plan: RetrievalPlan | dict[str, Any] | None = None,
306
346
  mode: str = "BALANCED", # FAST | BALANCED | DEEP
307
347
  explain: bool = False,
@@ -311,7 +351,7 @@ def get_context(
311
351
  include_build_artifacts: bool = False,
312
352
  max_symbols: int = 25,
313
353
  max_relationships: int = 30,
314
- max_files: int = 15,
354
+ max_files: int = 25,
315
355
  max_lines: int = 500,
316
356
  max_depth: int | None = None,
317
357
  max_package_depth: int | None = None,
@@ -363,7 +403,7 @@ def _get_context_impl(
363
403
  task: str | TaskSpec | dict[str, Any],
364
404
  intent: Intent | str | None = None,
365
405
  max_tokens: int = 20_000,
366
- top_k: int = 15,
406
+ top_k: int = 25,
367
407
  plan: RetrievalPlan | dict[str, Any] | None = None,
368
408
  mode: str = "BALANCED", # FAST | BALANCED | DEEP
369
409
  explain: bool = False,
@@ -374,7 +414,7 @@ def _get_context_impl(
374
414
  include_build_artifacts: bool = False,
375
415
  max_symbols: int = 25,
376
416
  max_relationships: int = 30,
377
- max_files: int = 15,
417
+ max_files: int = 25,
378
418
  max_lines: int = 500,
379
419
  max_depth: int | None = None,
380
420
  max_package_depth: int | None = None,
@@ -569,7 +609,11 @@ def _get_context_impl(
569
609
  break
570
610
  except Exception:
571
611
  pass
572
- is_disk_db = db_file_path is not None and Path(db_file_path).is_file()
612
+ is_disk_db = (
613
+ db_file_path is not None
614
+ and Path(db_file_path).is_file()
615
+ and os.name != "nt"
616
+ )
573
617
 
574
618
  queries_to_run: list[str] = _merged_queries if _merged_queries else [
575
619
  q for group in retrieval_plan.query_groups for q in group.queries
@@ -592,9 +636,10 @@ def _get_context_impl(
592
636
  def _exec_search(path: str | None, queries: list[str]) -> list[dict[str, object]]:
593
637
  items: list[dict[str, object]] = []
594
638
  if path:
595
- c = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
639
+ c = sqlite3.connect(str(path), timeout=15.0)
596
640
  c.row_factory = sqlite3.Row
597
641
  c.execute("PRAGMA busy_timeout = 15000")
642
+ c.execute("PRAGMA query_only = ON")
598
643
  try:
599
644
  for query in queries:
600
645
  for item in search(
@@ -628,9 +673,10 @@ def _get_context_impl(
628
673
  def _exec_routes(path: str | None) -> list[Any]:
629
674
  try:
630
675
  if path:
631
- c = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
676
+ c = sqlite3.connect(str(path), timeout=15.0)
632
677
  c.row_factory = sqlite3.Row
633
678
  c.execute("PRAGMA busy_timeout = 15000")
679
+ c.execute("PRAGMA query_only = ON")
634
680
  try:
635
681
  return c.execute(
636
682
  "SELECT route_path, http_method, handler_name, file_path, line, endpoint_id FROM framework_routes"
@@ -665,9 +711,10 @@ def _get_context_impl(
665
711
  archs: list[dict[str, object]] = []
666
712
  try:
667
713
  if path:
668
- c = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
714
+ c = sqlite3.connect(str(path), timeout=15.0)
669
715
  c.row_factory = sqlite3.Row
670
716
  c.execute("PRAGMA busy_timeout = 15000")
717
+ c.execute("PRAGMA query_only = ON")
671
718
  try:
672
719
  archs.append(get_architecture(c, repo))
673
720
  finally:
@@ -936,6 +983,28 @@ def _get_context_impl(
936
983
  if res.qualified_name and _guard.allows_symbol(res.qualified_name) and res.qualified_name not in _seen_seeds:
937
984
  _seen_seeds.add(res.qualified_name)
938
985
  ordered_seeds.append(res.qualified_name)
986
+ if res.file_path:
987
+ try:
988
+ f_rows = con.execute(
989
+ "SELECT canonical_id FROM symbols WHERE path = ? LIMIT 5",
990
+ (res.file_path,),
991
+ ).fetchall()
992
+ for fr in f_rows:
993
+ fs_cid = str(fr["canonical_id"])
994
+ if fs_cid and _guard.allows_canonical_id(fs_cid) and fs_cid not in _seen_seeds:
995
+ _seen_seeds.add(fs_cid)
996
+ ordered_seeds.append(fs_cid)
997
+ e_rows = con.execute(
998
+ "SELECT DISTINCT target FROM graph_edges WHERE file = ? AND relationship IN ('CALLS', 'IMPORTS') LIMIT 5",
999
+ (res.file_path,),
1000
+ ).fetchall()
1001
+ for er in e_rows:
1002
+ e_tgt = str(er["target"])
1003
+ if e_tgt and _guard.allows_symbol(e_tgt) and e_tgt not in _seen_seeds:
1004
+ _seen_seeds.add(e_tgt)
1005
+ ordered_seeds.append(e_tgt)
1006
+ except Exception:
1007
+ pass
939
1008
 
940
1009
  for ep in entry_points_out:
941
1010
  h = str(ep.get("handler", ""))
@@ -1305,6 +1374,31 @@ def _get_context_impl(
1305
1374
  )
1306
1375
  timing.tests_ms = (time.perf_counter() - t_tests_start) * 1000
1307
1376
 
1377
+ # Fallback seeding: if candidate_dicts is empty, seed with top symbols from index
1378
+ if not candidate_dicts:
1379
+ try:
1380
+ fb_rows = con.execute("""
1381
+ SELECT name, canonical_id, kind, path, start_line, end_line
1382
+ FROM symbols
1383
+ WHERE kind IN ('class', 'struct', 'interface', 'function', 'method')
1384
+ ORDER BY start_line
1385
+ LIMIT 20;
1386
+ """).fetchall()
1387
+ for r in fb_rows:
1388
+ candidate_dicts.append({
1389
+ "file": r[3],
1390
+ "symbol": r[0],
1391
+ "canonical_id": r[1],
1392
+ "kind": r[2],
1393
+ "start_line": r[4] or 1,
1394
+ "end_line": r[5] or 1,
1395
+ "score": 0.5,
1396
+ "snippet": "",
1397
+ "relationship": "CORE_SYMBOL",
1398
+ })
1399
+ except Exception:
1400
+ pass
1401
+
1308
1402
  # Pre-ranking artifact & package annotation on candidate_dicts
1309
1403
  from codegraph.indexing.classifier import classify_file
1310
1404
  from codegraph.security import is_sensitive_path
@@ -1430,10 +1524,15 @@ def _get_context_impl(
1430
1524
  "SELECT canonical_id FROM symbols WHERE (canonical_id=? OR qualified_name=? OR name=?) AND path=? LIMIT 1",
1431
1525
  (item.symbol, item.symbol, item.symbol, item.file),
1432
1526
  ).fetchone()
1433
- if not srow:
1527
+ if not srow and not item.file:
1528
+ srow = con.execute(
1529
+ "SELECT canonical_id FROM symbols WHERE canonical_id=? OR qualified_name=? LIMIT 1",
1530
+ (item.symbol, item.symbol),
1531
+ ).fetchone()
1532
+ elif not srow and item.symbol:
1434
1533
  srow = con.execute(
1435
- "SELECT canonical_id FROM symbols WHERE canonical_id=? OR qualified_name=? OR name=? LIMIT 1",
1436
- (item.symbol, item.symbol, item.symbol),
1534
+ "SELECT canonical_id FROM symbols WHERE canonical_id=? LIMIT 1",
1535
+ (item.symbol,),
1437
1536
  ).fetchone()
1438
1537
  if srow:
1439
1538
  canon = srow["canonical_id"]
@@ -1525,12 +1624,12 @@ def _get_context_impl(
1525
1624
  ).fetchone()
1526
1625
  else:
1527
1626
  row = con.execute(
1528
- "SELECT canonical_id, kind FROM symbols WHERE (qualified_name=? OR name=?) AND path=? LIMIT 1",
1529
- (sym_name, sym_name, it.file_path),
1627
+ "SELECT canonical_id, kind FROM symbols WHERE (canonical_id=? OR qualified_name=? OR name=?) AND path=? LIMIT 1",
1628
+ (sym_name, sym_name, sym_name, it.file_path),
1530
1629
  ).fetchone()
1531
- if not row:
1630
+ if not row and not it.file_path:
1532
1631
  row = con.execute(
1533
- "SELECT canonical_id, kind FROM symbols WHERE qualified_name=? OR name=? LIMIT 1",
1632
+ "SELECT canonical_id, kind FROM symbols WHERE canonical_id=? OR qualified_name=? LIMIT 1",
1534
1633
  (sym_name, sym_name),
1535
1634
  ).fetchone()
1536
1635
  cid = known_cid or (row["canonical_id"] if row and "canonical_id" in row.keys() else None)
@@ -2040,22 +2139,34 @@ def _get_context_impl(
2040
2139
  budget=budget.as_dict(),
2041
2140
  execution=exec_dict,
2042
2141
  mode=mode_upper,
2043
- entry_points=entry_points_out,
2044
- framework_facts=framework_facts_out,
2045
- architecture=architecture_out,
2046
- git_changes=git_changes_out,
2047
- git_facts=git_changes_out,
2142
+ entry_points=[
2143
+ r for r in entry_points_out
2144
+ if any(sp in str(r.get("file", "")) for sp in selected_paths)
2145
+ ][:5] if (max_tokens <= 4000 and entry_points_out) else entry_points_out[:10],
2146
+ framework_facts=[
2147
+ f for f in framework_facts_out
2148
+ if any(sp in str(f.get("file", "")) for sp in selected_paths)
2149
+ ][:10] if (max_tokens <= 4000 and framework_facts_out) else framework_facts_out[:20],
2150
+ architecture=architecture_out[:5] if max_tokens <= 4000 else architecture_out,
2151
+ git_changes=git_changes_out[:5] if max_tokens <= 4000 else git_changes_out,
2152
+ git_facts=git_changes_out[:5] if max_tokens <= 4000 else git_changes_out,
2048
2153
  assumptions=assumptions_out,
2049
2154
  unknowns=unknowns_out,
2050
2155
  conflicts=conflicts_out,
2051
2156
  metadata=metadata_dict,
2052
2157
  target=target_dict,
2053
- routes=entry_points_out,
2054
- packages=packages_out,
2158
+ routes=[
2159
+ r for r in entry_points_out
2160
+ if any(sp in str(r.get("file", "")) for sp in selected_paths)
2161
+ ][:5] if (max_tokens <= 4000 and entry_points_out) else entry_points_out[:10],
2162
+ packages=packages_out[:5] if max_tokens <= 4000 else packages_out,
2055
2163
  git_impact=git_impact_dict,
2056
- findings=findings_out,
2164
+ findings=findings_out[:10] if max_tokens <= 4000 else findings_out,
2057
2165
  coverage=coverage_dict,
2058
- database=database_out,
2166
+ database=[
2167
+ d for d in database_out
2168
+ if any(sp in str(d.get("file", "")) for sp in selected_paths)
2169
+ ][:5] if (max_tokens <= 4000 and database_out) else database_out[:15],
2059
2170
  runtime=runtime_out,
2060
2171
  reconciliation=reconciliation_out,
2061
2172
  symbols=symbols_out,
@@ -69,6 +69,8 @@ def _run_git(repository: Path, *args: str, timeout: int = 10) -> str | None:
69
69
  cwd=str(repository),
70
70
  capture_output=True,
71
71
  text=True,
72
+ encoding="utf-8",
73
+ errors="replace",
72
74
  timeout=timeout,
73
75
  )
74
76
  return res.stdout if res.returncode == 0 else None
@@ -19,6 +19,7 @@ from .interrogation import (
19
19
  get_db_impact,
20
20
  get_db_schema,
21
21
  get_db_table,
22
+ get_route_db_lineage,
22
23
  )
23
24
  from .models import (
24
25
  DatabaseEntity,
@@ -29,15 +30,27 @@ from .models import (
29
30
  normalize_dialect,
30
31
  normalize_schema_name,
31
32
  )
33
+ from .schema_drift import (
34
+ DriftSeverity,
35
+ DriftType,
36
+ SchemaDriftIssue,
37
+ SchemaFieldSpec,
38
+ detect_schema_drift,
39
+ )
32
40
 
33
41
  __all__ = [
34
42
  "DatabaseEntity",
35
43
  "DatabaseEntityKind",
36
44
  "DatabaseExtractionResult",
37
45
  "DatabaseQueryFact",
46
+ "DriftSeverity",
47
+ "DriftType",
38
48
  "MigrationFact",
49
+ "SchemaDriftIssue",
50
+ "SchemaFieldSpec",
39
51
  "build_db_canonical_id",
40
52
  "detect_file_dialects",
53
+ "detect_schema_drift",
41
54
  "extract_database_from_file",
42
55
  "find_db_callers",
43
56
  "find_db_columns",
@@ -50,6 +63,7 @@ __all__ = [
50
63
  "get_db_impact",
51
64
  "get_db_schema",
52
65
  "get_db_table",
66
+ "get_route_db_lineage",
53
67
  "has_potential_database_activity",
54
68
  "has_potential_orm_models",
55
69
  "normalize_dialect",