codegraph-engine 3.0.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 (130) hide show
  1. codegraph/__init__.py +37 -0
  2. codegraph/agent.py +26 -0
  3. codegraph/agent_brain.py +2212 -0
  4. codegraph/agent_capabilities.py +4058 -0
  5. codegraph/agent_rules.py +531 -0
  6. codegraph/api_drift.py +455 -0
  7. codegraph/architecture.py +371 -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/audit.py +106 -0
  22. codegraph/binding_resolver.py +616 -0
  23. codegraph/branch_comparison.py +197 -0
  24. codegraph/cache.py +95 -0
  25. codegraph/change_impact.py +547 -0
  26. codegraph/cli.py +2436 -0
  27. codegraph/cli_output.py +205 -0
  28. codegraph/config.py +45 -0
  29. codegraph/constraints.py +238 -0
  30. codegraph/context.py +2182 -0
  31. codegraph/context_freshness.py +351 -0
  32. codegraph/database/__init__.py +72 -0
  33. codegraph/database/extractor.py +3651 -0
  34. codegraph/database/interrogation.py +1494 -0
  35. codegraph/database/models.py +310 -0
  36. codegraph/database/schema_drift.py +862 -0
  37. codegraph/epistemic.py +200 -0
  38. codegraph/errors.py +282 -0
  39. codegraph/evidence/__init__.py +15 -0
  40. codegraph/evidence/citations.py +418 -0
  41. codegraph/evidence_contract.py +486 -0
  42. codegraph/frameworks.py +960 -0
  43. codegraph/frameworks_nestjs.py +502 -0
  44. codegraph/frameworks_nextjs.py +337 -0
  45. codegraph/frameworks_react.py +457 -0
  46. codegraph/freshness.py +335 -0
  47. codegraph/frontend_html.py +109 -0
  48. codegraph/git.py +362 -0
  49. codegraph/git_state.py +545 -0
  50. codegraph/graph/__init__.py +46 -0
  51. codegraph/graph/models.py +56 -0
  52. codegraph/graph/traversal.py +1993 -0
  53. codegraph/indexing/__init__.py +24 -0
  54. codegraph/indexing/classifier.py +564 -0
  55. codegraph/indexing/indexer.py +2578 -0
  56. codegraph/indexing/models.py +427 -0
  57. codegraph/indexing/parser.py +3404 -0
  58. codegraph/indexing/pool.py +136 -0
  59. codegraph/indexing/scanner.py +211 -0
  60. codegraph/indexing/telemetry.py +326 -0
  61. codegraph/indexing/templates.py +418 -0
  62. codegraph/indexing/test_framework.py +116 -0
  63. codegraph/installer.py +1702 -0
  64. codegraph/interrogation.py +2355 -0
  65. codegraph/llm/__init__.py +3 -0
  66. codegraph/llm/base.py +15 -0
  67. codegraph/llm/context.py +20 -0
  68. codegraph/mcp/__init__.py +3 -0
  69. codegraph/mcp/server.py +1476 -0
  70. codegraph/mcp_diagnostics.py +882 -0
  71. codegraph/memory/__init__.py +3 -0
  72. codegraph/memory/store.py +46 -0
  73. codegraph/models.py +310 -0
  74. codegraph/monorepo.py +925 -0
  75. codegraph/observability.py +262 -0
  76. codegraph/optimizer.py +1014 -0
  77. codegraph/planner.py +417 -0
  78. codegraph/process_lifecycle.py +1153 -0
  79. codegraph/py.typed +1 -0
  80. codegraph/query_expansion.py +199 -0
  81. codegraph/ranking.py +408 -0
  82. codegraph/refactor/__init__.py +36 -0
  83. codegraph/refactor/models.py +114 -0
  84. codegraph/refactor/renamer.py +844 -0
  85. codegraph/refactor/transactions.py +414 -0
  86. codegraph/resolver.py +3968 -0
  87. codegraph/resources/__init__.py +46 -0
  88. codegraph/resources/cache.py +117 -0
  89. codegraph/resources/coalescer.py +83 -0
  90. codegraph/resources/debouncer.py +98 -0
  91. codegraph/resources/governor.py +219 -0
  92. codegraph/resources/monitor.py +102 -0
  93. codegraph/resources/policy.py +123 -0
  94. codegraph/retrieval_policy.py +320 -0
  95. codegraph/roblox.py +2174 -0
  96. codegraph/route_composer.py +363 -0
  97. codegraph/route_topology.py +172 -0
  98. codegraph/runtime/__init__.py +51 -0
  99. codegraph/runtime/collector.py +155 -0
  100. codegraph/runtime/db_watcher.py +191 -0
  101. codegraph/runtime/ingestor.py +692 -0
  102. codegraph/runtime/models.py +130 -0
  103. codegraph/runtime/port_inspector.py +304 -0
  104. codegraph/runtime/reconciliation.py +492 -0
  105. codegraph/runtime/runner.py +353 -0
  106. codegraph/runtime/trace_linker.py +175 -0
  107. codegraph/search/__init__.py +25 -0
  108. codegraph/search/hybrid.py +846 -0
  109. codegraph/search/semantic.py +28 -0
  110. codegraph/security/__init__.py +51 -0
  111. codegraph/security/paths.py +189 -0
  112. codegraph/security/redaction.py +633 -0
  113. codegraph/semantic_conflicts.py +270 -0
  114. codegraph/semantic_decorators.py +372 -0
  115. codegraph/structural_diff.py +542 -0
  116. codegraph/styles.py +144 -0
  117. codegraph/symbol_history.py +277 -0
  118. codegraph/target_resolver.py +348 -0
  119. codegraph/task.py +637 -0
  120. codegraph/tool_selection_eval.py +1158 -0
  121. codegraph/tsconfig.py +236 -0
  122. codegraph/ui/__init__.py +6 -0
  123. codegraph/ui/server.py +755 -0
  124. codegraph/watcher.py +323 -0
  125. codegraph_engine-3.0.0.dist-info/METADATA +859 -0
  126. codegraph_engine-3.0.0.dist-info/RECORD +130 -0
  127. codegraph_engine-3.0.0.dist-info/WHEEL +6 -0
  128. codegraph_engine-3.0.0.dist-info/entry_points.txt +2 -0
  129. codegraph_engine-3.0.0.dist-info/licenses/LICENSE +21 -0
  130. codegraph_engine-3.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,3 @@
1
+ from .store import MemoryStore
2
+
3
+ __all__ = ["MemoryStore"]
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ import builtins
4
+ import sqlite3
5
+ from collections.abc import Iterator
6
+ from contextlib import contextmanager
7
+ from pathlib import Path
8
+
9
+
10
+ class MemoryStore:
11
+ def __init__(self, db_path: Path) -> None:
12
+ self.db_path = db_path
13
+ with self.session() as con:
14
+ con.execute("CREATE TABLE IF NOT EXISTS memory (key TEXT PRIMARY KEY, value TEXT NOT NULL)")
15
+
16
+ def connect(self) -> sqlite3.Connection:
17
+ return sqlite3.connect(self.db_path)
18
+
19
+ @contextmanager
20
+ def session(self) -> Iterator[sqlite3.Connection]:
21
+ con = self.connect()
22
+ try:
23
+ yield con
24
+ con.commit()
25
+ except BaseException:
26
+ con.rollback()
27
+ raise
28
+ finally:
29
+ con.close()
30
+
31
+ def list(self) -> builtins.list[tuple[str, str]]:
32
+ with self.session() as con:
33
+ return list(con.execute("SELECT key, value FROM memory ORDER BY key"))
34
+
35
+ def search(self, query: str, limit: int = 20) -> builtins.list[tuple[str, str]]:
36
+ if not query.strip():
37
+ raise ValueError("memory query must be non-empty")
38
+ with self.session() as con:
39
+ return list(con.execute(
40
+ "SELECT key, value FROM memory WHERE key LIKE ? OR value LIKE ? ORDER BY key LIMIT ?",
41
+ (f"%{query}%", f"%{query}%", limit),
42
+ ))
43
+
44
+ def clear(self) -> None:
45
+ with self.session() as con:
46
+ con.execute("DELETE FROM memory")
codegraph/models.py ADDED
@@ -0,0 +1,310 @@
1
+ """Unified domain models for the CodeGraph intelligence engine."""
2
+ from __future__ import annotations
3
+
4
+ from dataclasses import asdict, dataclass, field
5
+ from typing import Literal
6
+
7
+ from pydantic import BaseModel
8
+
9
+ from codegraph.graph.models import GraphEdge
10
+ from codegraph.indexing.models import (
11
+ CallRef,
12
+ Chunk,
13
+ ImportRef,
14
+ InheritanceRef,
15
+ Reference,
16
+ Symbol,
17
+ build_canonical_id,
18
+ normalize_module,
19
+ )
20
+
21
+ Import = ImportRef
22
+ Call = CallRef
23
+
24
+ NodeType = Literal[
25
+ "FILE",
26
+ "MODULE",
27
+ "CLASS",
28
+ "FUNCTION",
29
+ "METHOD",
30
+ "API_ENDPOINT",
31
+ "API",
32
+ "TEST",
33
+ "TYPE",
34
+ "CONFIG",
35
+ "EXTERNAL_SERVICE",
36
+ ]
37
+
38
+ EdgeType = Literal[
39
+ "DEFINES",
40
+ "CONTAINS",
41
+ "IMPORTS",
42
+ "EXPORTS",
43
+ "REEXPORTS",
44
+ "CALLS",
45
+ "CALLED_BY",
46
+ "POSSIBLE_CALLS",
47
+ "REFERENCES",
48
+ "EXTENDS",
49
+ "IMPLEMENTS",
50
+ "USES",
51
+ "ROUTES_TO",
52
+ "MOUNTS",
53
+ "RESOLVES_TO",
54
+ "REGISTERS",
55
+ "DISPATCHES_TO",
56
+ "EVENT_LISTENER",
57
+ "TASK_HANDLER",
58
+ "COMMAND_HANDLER",
59
+ "DISPATCHES_TASK",
60
+ "TRIGGERS_SIGNAL",
61
+ "HANDLES_SIGNAL",
62
+ "RENDERS_TEMPLATE",
63
+ "DISPATCHES_FORWARD",
64
+ "TOOL_HANDLER",
65
+ "PIPELINE_STEP",
66
+ "TESTS",
67
+ "TESTS_ROUTE",
68
+ "TESTS_SYMBOL",
69
+ "TESTS_PROVIDER",
70
+ "TESTS_EVENT_HANDLER",
71
+ "DEPENDS_ON",
72
+ "CONFIGURES",
73
+ "INJECTS",
74
+ "PROVIDES",
75
+ "RESOLVES_DEPENDENCY",
76
+ ]
77
+
78
+ ErrorCategory = Literal[
79
+ "INVALID_INPUT",
80
+ "NOT_FOUND",
81
+ "SECURITY_DENIED",
82
+ "STALE_INDEX",
83
+ "INDEX_STALE",
84
+ "INDEX_UNAVAILABLE",
85
+ "PARSER_ERROR",
86
+ "UNSUPPORTED_LANGUAGE",
87
+ "STORAGE_ERROR",
88
+ "INTERNAL_ERROR",
89
+ ]
90
+
91
+
92
+ @dataclass(frozen=True)
93
+ class Repository:
94
+ path: str
95
+ name: str
96
+ head_commit: str | None = None
97
+ branch: str | None = None
98
+
99
+
100
+ @dataclass(frozen=True)
101
+ class File:
102
+ path: str
103
+ hash: str
104
+ language: str
105
+ indexed_at: int = 0
106
+ status: str = "ok" # ok | parse_failed
107
+ parse_error: str | None = None
108
+
109
+
110
+ @dataclass(frozen=True)
111
+ class SymbolLocation:
112
+ canonical_id: str
113
+ path: str
114
+ start_line: int
115
+ end_line: int
116
+ source_hash: str = ""
117
+
118
+
119
+ @dataclass(frozen=True)
120
+ class GraphNode:
121
+ node_id: str
122
+ node_type: str
123
+ name: str
124
+ file: str | None = None
125
+ start_line: int | None = None
126
+ end_line: int | None = None
127
+ metadata: dict[str, object] = field(default_factory=dict)
128
+
129
+ def as_dict(self) -> dict[str, object]:
130
+ return asdict(self)
131
+
132
+
133
+ @dataclass(frozen=True)
134
+ class RepositorySnapshot:
135
+ repository: str
136
+ indexed_commit: str | None
137
+ current_commit: str | None
138
+ parser_version: str
139
+ schema_version: int
140
+ index_generation: int
141
+ timestamp: int
142
+ file_count: int
143
+ symbol_count: int
144
+ reference_count: int
145
+
146
+
147
+ @dataclass(frozen=True)
148
+ class FreshnessState:
149
+ status: str # FRESH | PARTIALLY_STALE | STALE | UNKNOWN
150
+ indexed_commit: str | None
151
+ current_commit: str | None
152
+ modified_files: list[str]
153
+ deleted_files: list[str]
154
+ added_files: list[str]
155
+ parse_failed_files: list[str]
156
+ detail: str
157
+
158
+
159
+ @dataclass(frozen=True)
160
+ class ContextCandidate:
161
+ file: str
162
+ symbol: str | None
163
+ canonical_id: str | None
164
+ kind: str
165
+ start_line: int
166
+ end_line: int
167
+ snippet: str
168
+ confidence: str = "HIGH"
169
+ freshness: str = "FRESH"
170
+ relationship: str = ""
171
+ distance: int = 0
172
+ score: float = 0.0
173
+
174
+
175
+ class TestRelationship(BaseModel):
176
+ schema_version: str = "1.0"
177
+ file: str
178
+ symbol: str | None = None
179
+ target_symbol: str | None = None
180
+ classification: str = "VERIFIED_TEST" # VERIFIED_TEST | POSSIBLE_TEST
181
+ relationship: str
182
+ confidence: str
183
+ start_line: int = 1
184
+ evidence: str
185
+
186
+
187
+ class ImpactItem(BaseModel):
188
+ symbol: str | None = None
189
+ file: str
190
+ impact_type: str # direct | indirect | potential | test | api | config | doc
191
+ relationship: str = "CALLS"
192
+ confidence: str = "HIGH"
193
+ label: str = "verified" # verified | inferred | possible
194
+ distance: int = 1
195
+ line: int = 1
196
+ evidence: str = ""
197
+
198
+
199
+ class ImpactResult(BaseModel):
200
+ schema_version: str = "2.0"
201
+ subject: str
202
+ canonical_id: str | None = None
203
+ direct_callers: list[dict[str, object]] = []
204
+ transitive_callers: list[dict[str, object]] = []
205
+ directly_affected: list[dict[str, object]] = []
206
+ indirectly_affected: list[dict[str, object]] = []
207
+ potential: list[dict[str, object]] = []
208
+ dependencies: list[dict[str, object]] = []
209
+ dependent_modules: list[dict[str, object]] = []
210
+ related_apis: list[dict[str, object]] = []
211
+ related_tests: list[dict[str, object]] = []
212
+ configuration: list[dict[str, object]] = []
213
+ documentation: list[dict[str, object]] = []
214
+ recent_modifications: list[dict[str, object]] = []
215
+ evidence: list[dict[str, object]] = []
216
+ label_legend: dict[str, str] = {}
217
+ note: str = (
218
+ "Static analysis cannot confirm runtime behavior. "
219
+ "Do not assert failure solely from static dependency data."
220
+ )
221
+
222
+ def as_dict(self) -> dict[str, object]:
223
+ return self.model_dump()
224
+
225
+
226
+ class ArchitectureNode(BaseModel):
227
+ id: str
228
+ name: str
229
+ layer: str # entry_point | route | controller | service | repository | model | config | test | external
230
+ file: str
231
+ line: int = 1
232
+ confidence: str = "HIGH"
233
+
234
+
235
+ class ArchitectureEdge(BaseModel):
236
+ source: str
237
+ target: str
238
+ relationship: str
239
+ confidence: str = "HIGH"
240
+ evidence: str = ""
241
+
242
+
243
+ class MCPError(BaseModel):
244
+ schema_version: str = "1.0"
245
+ error_code: ErrorCategory
246
+ message: str
247
+ details: dict[str, object] = {}
248
+
249
+ def as_dict(self) -> dict[str, object]:
250
+ return self.model_dump()
251
+
252
+
253
+ @dataclass
254
+ class ObservabilityMetrics:
255
+ index_duration_ms: float = 0.0
256
+ files_scanned: int = 0
257
+ files_changed: int = 0
258
+ files_unchanged: int = 0
259
+ files_removed: int = 0
260
+ files_parse_failed: int = 0
261
+ symbols_count: int = 0
262
+ references_count: int = 0
263
+ graph_edges_count: int = 0
264
+ search_latency_ms: float = 0.0
265
+ context_compile_latency_ms: float = 0.0
266
+ database_size_bytes: int = 0
267
+ cache_hits: int = 0
268
+ cache_misses: int = 0
269
+
270
+ @property
271
+ def cache_hit_rate(self) -> float:
272
+ total = self.cache_hits + self.cache_misses
273
+ return round(self.cache_hits / total, 3) if total > 0 else 0.0
274
+
275
+ def as_dict(self) -> dict[str, object]:
276
+ d = asdict(self)
277
+ d["cache_hit_rate"] = self.cache_hit_rate
278
+ return d
279
+
280
+
281
+ __all__ = [
282
+ "ArchitectureEdge",
283
+ "ArchitectureNode",
284
+ "Call",
285
+ "CallRef",
286
+ "Chunk",
287
+ "ContextCandidate",
288
+ "EdgeType",
289
+ "ErrorCategory",
290
+ "File",
291
+ "FreshnessState",
292
+ "GraphEdge",
293
+ "GraphNode",
294
+ "ImpactItem",
295
+ "ImpactResult",
296
+ "Import",
297
+ "ImportRef",
298
+ "InheritanceRef",
299
+ "MCPError",
300
+ "NodeType",
301
+ "ObservabilityMetrics",
302
+ "Reference",
303
+ "Repository",
304
+ "RepositorySnapshot",
305
+ "Symbol",
306
+ "SymbolLocation",
307
+ "TestRelationship",
308
+ "build_canonical_id",
309
+ "normalize_module",
310
+ ]