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.
- codegraph/__init__.py +37 -0
- codegraph/agent.py +26 -0
- codegraph/agent_brain.py +2212 -0
- codegraph/agent_capabilities.py +4058 -0
- codegraph/agent_rules.py +531 -0
- codegraph/api_drift.py +455 -0
- codegraph/architecture.py +371 -0
- codegraph/async_queue/__init__.py +50 -0
- codegraph/async_queue/detectors/__init__.py +48 -0
- codegraph/async_queue/detectors/celery.py +160 -0
- codegraph/async_queue/detectors/kafka.py +168 -0
- codegraph/async_queue/detectors/rabbitmq.py +116 -0
- codegraph/async_queue/detectors/redis.py +130 -0
- codegraph/async_queue/detectors/sqs.py +135 -0
- codegraph/async_queue/models.py +161 -0
- codegraph/async_queue/otel_models.py +74 -0
- codegraph/async_queue/otel_parser.py +337 -0
- codegraph/async_queue/reconciler.py +427 -0
- codegraph/async_queue/scanner.py +291 -0
- codegraph/async_queue/traversal.py +447 -0
- codegraph/audit.py +106 -0
- codegraph/binding_resolver.py +616 -0
- codegraph/branch_comparison.py +197 -0
- codegraph/cache.py +95 -0
- codegraph/change_impact.py +547 -0
- codegraph/cli.py +2436 -0
- codegraph/cli_output.py +205 -0
- codegraph/config.py +45 -0
- codegraph/constraints.py +238 -0
- codegraph/context.py +2182 -0
- codegraph/context_freshness.py +351 -0
- codegraph/database/__init__.py +72 -0
- codegraph/database/extractor.py +3651 -0
- codegraph/database/interrogation.py +1494 -0
- codegraph/database/models.py +310 -0
- codegraph/database/schema_drift.py +862 -0
- codegraph/epistemic.py +200 -0
- codegraph/errors.py +282 -0
- codegraph/evidence/__init__.py +15 -0
- codegraph/evidence/citations.py +418 -0
- codegraph/evidence_contract.py +486 -0
- codegraph/frameworks.py +960 -0
- codegraph/frameworks_nestjs.py +502 -0
- codegraph/frameworks_nextjs.py +337 -0
- codegraph/frameworks_react.py +457 -0
- codegraph/freshness.py +335 -0
- codegraph/frontend_html.py +109 -0
- codegraph/git.py +362 -0
- codegraph/git_state.py +545 -0
- codegraph/graph/__init__.py +46 -0
- codegraph/graph/models.py +56 -0
- codegraph/graph/traversal.py +1993 -0
- codegraph/indexing/__init__.py +24 -0
- codegraph/indexing/classifier.py +564 -0
- codegraph/indexing/indexer.py +2578 -0
- codegraph/indexing/models.py +427 -0
- codegraph/indexing/parser.py +3404 -0
- codegraph/indexing/pool.py +136 -0
- codegraph/indexing/scanner.py +211 -0
- codegraph/indexing/telemetry.py +326 -0
- codegraph/indexing/templates.py +418 -0
- codegraph/indexing/test_framework.py +116 -0
- codegraph/installer.py +1702 -0
- codegraph/interrogation.py +2355 -0
- codegraph/llm/__init__.py +3 -0
- codegraph/llm/base.py +15 -0
- codegraph/llm/context.py +20 -0
- codegraph/mcp/__init__.py +3 -0
- codegraph/mcp/server.py +1476 -0
- codegraph/mcp_diagnostics.py +882 -0
- codegraph/memory/__init__.py +3 -0
- codegraph/memory/store.py +46 -0
- codegraph/models.py +310 -0
- codegraph/monorepo.py +925 -0
- codegraph/observability.py +262 -0
- codegraph/optimizer.py +1014 -0
- codegraph/planner.py +417 -0
- codegraph/process_lifecycle.py +1153 -0
- codegraph/py.typed +1 -0
- codegraph/query_expansion.py +199 -0
- codegraph/ranking.py +408 -0
- codegraph/refactor/__init__.py +36 -0
- codegraph/refactor/models.py +114 -0
- codegraph/refactor/renamer.py +844 -0
- codegraph/refactor/transactions.py +414 -0
- codegraph/resolver.py +3968 -0
- codegraph/resources/__init__.py +46 -0
- codegraph/resources/cache.py +117 -0
- codegraph/resources/coalescer.py +83 -0
- codegraph/resources/debouncer.py +98 -0
- codegraph/resources/governor.py +219 -0
- codegraph/resources/monitor.py +102 -0
- codegraph/resources/policy.py +123 -0
- codegraph/retrieval_policy.py +320 -0
- codegraph/roblox.py +2174 -0
- codegraph/route_composer.py +363 -0
- codegraph/route_topology.py +172 -0
- codegraph/runtime/__init__.py +51 -0
- codegraph/runtime/collector.py +155 -0
- codegraph/runtime/db_watcher.py +191 -0
- codegraph/runtime/ingestor.py +692 -0
- codegraph/runtime/models.py +130 -0
- codegraph/runtime/port_inspector.py +304 -0
- codegraph/runtime/reconciliation.py +492 -0
- codegraph/runtime/runner.py +353 -0
- codegraph/runtime/trace_linker.py +175 -0
- codegraph/search/__init__.py +25 -0
- codegraph/search/hybrid.py +846 -0
- codegraph/search/semantic.py +28 -0
- codegraph/security/__init__.py +51 -0
- codegraph/security/paths.py +189 -0
- codegraph/security/redaction.py +633 -0
- codegraph/semantic_conflicts.py +270 -0
- codegraph/semantic_decorators.py +372 -0
- codegraph/structural_diff.py +542 -0
- codegraph/styles.py +144 -0
- codegraph/symbol_history.py +277 -0
- codegraph/target_resolver.py +348 -0
- codegraph/task.py +637 -0
- codegraph/tool_selection_eval.py +1158 -0
- codegraph/tsconfig.py +236 -0
- codegraph/ui/__init__.py +6 -0
- codegraph/ui/server.py +755 -0
- codegraph/watcher.py +323 -0
- codegraph_engine-3.0.0.dist-info/METADATA +859 -0
- codegraph_engine-3.0.0.dist-info/RECORD +130 -0
- codegraph_engine-3.0.0.dist-info/WHEEL +6 -0
- codegraph_engine-3.0.0.dist-info/entry_points.txt +2 -0
- codegraph_engine-3.0.0.dist-info/licenses/LICENSE +21 -0
- codegraph_engine-3.0.0.dist-info/top_level.txt +1 -0
codegraph/tsconfig.py
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""TypeScript and JavaScript Path Alias Resolution (tsconfig.json / jsconfig.json).
|
|
2
|
+
|
|
3
|
+
Provides deterministic resolution of compilerOptions.paths and baseUrl across
|
|
4
|
+
monorepos, Next.js, Vite, and React projects without external dependencies.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import posixpath
|
|
10
|
+
import re
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def strip_json_comments(text: str) -> str:
|
|
16
|
+
"""Strip single-line and multi-line comments and trailing commas from tsconfig/jsconfig JSON."""
|
|
17
|
+
# Remove block comments /* ... */
|
|
18
|
+
text = re.sub(r"/\*[\s\S]*?\*/", "", text)
|
|
19
|
+
# Remove line comments // ... (not inside quotes)
|
|
20
|
+
lines: list[str] = []
|
|
21
|
+
for line in text.splitlines():
|
|
22
|
+
# Match // not preceded by a quote mark
|
|
23
|
+
cleaned_line = re.sub(r'(?<![:"\'\\])//.*$', '', line)
|
|
24
|
+
lines.append(cleaned_line)
|
|
25
|
+
cleaned = "\n".join(lines)
|
|
26
|
+
# Remove trailing commas before } or ]
|
|
27
|
+
cleaned = re.sub(r",\s*([}\]])", r"\1", cleaned)
|
|
28
|
+
return cleaned
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class TsConfig:
|
|
33
|
+
config_path: str
|
|
34
|
+
base_dir: str
|
|
35
|
+
base_url: str
|
|
36
|
+
paths: dict[str, tuple[str, ...]] = field(default_factory=dict)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TsConfigResolver:
|
|
40
|
+
"""Manages tsconfig.json and jsconfig.json path mappings across workspaces."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, configs: list[TsConfig] | None = None) -> None:
|
|
43
|
+
self.configs: list[TsConfig] = configs or []
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def load_from_repo(cls, repo_root: Path) -> TsConfigResolver:
|
|
47
|
+
"""Scan workspace for tsconfig.json, jsconfig.json, and vite.config.* files."""
|
|
48
|
+
configs: list[TsConfig] = []
|
|
49
|
+
candidates = (
|
|
50
|
+
list(repo_root.glob("**/tsconfig*.json"))
|
|
51
|
+
+ list(repo_root.glob("**/jsconfig*.json"))
|
|
52
|
+
+ list(repo_root.glob("**/vite.config.*"))
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
for c_path in candidates:
|
|
56
|
+
# Skip node_modules or build outputs
|
|
57
|
+
parts = c_path.parts
|
|
58
|
+
if any(p in ("node_modules", ".git", "dist", "build", ".next", ".cache") for p in parts):
|
|
59
|
+
continue
|
|
60
|
+
if c_path.name.startswith("vite.config."):
|
|
61
|
+
cfg = cls._parse_vite_config(c_path, repo_root)
|
|
62
|
+
else:
|
|
63
|
+
cfg = cls._parse_single_config(c_path, repo_root)
|
|
64
|
+
if cfg:
|
|
65
|
+
configs.append(cfg)
|
|
66
|
+
|
|
67
|
+
# Sort configs: deepest path first for nearest-config resolution
|
|
68
|
+
configs.sort(key=lambda c: len(c.base_dir), reverse=True)
|
|
69
|
+
return cls(configs)
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def _parse_vite_config(file_path: Path, repo_root: Path) -> TsConfig | None:
|
|
73
|
+
try:
|
|
74
|
+
content = file_path.read_text(encoding="utf-8", errors="replace")
|
|
75
|
+
parsed_paths: dict[str, tuple[str, ...]] = {}
|
|
76
|
+
|
|
77
|
+
# 1. Object alias: alias: { '@': path.resolve(__dirname, './src'), ... }
|
|
78
|
+
alias_match = re.search(r"alias\s*:\s*\{([^}]+)\}", content)
|
|
79
|
+
if alias_match:
|
|
80
|
+
entries = re.findall(
|
|
81
|
+
r"""['"]([^'"]+)['"]\s*:\s*(?:(?:path\.)?resolve\([^)]*['"]([^'"]+)['"]\)|['"]([^'"]+)['"])""",
|
|
82
|
+
alias_match.group(1),
|
|
83
|
+
)
|
|
84
|
+
for key, target1, target2 in entries:
|
|
85
|
+
raw_target = (target1 or target2 or "").strip().replace("\\", "/").lstrip("./")
|
|
86
|
+
if raw_target:
|
|
87
|
+
clean_key = key.rstrip("/")
|
|
88
|
+
parsed_paths[f"{clean_key}/*"] = (f"{raw_target}/*",)
|
|
89
|
+
parsed_paths[clean_key] = (raw_target,)
|
|
90
|
+
|
|
91
|
+
# 2. Array alias: alias: [ { find: '@', replacement: path.resolve(__dirname, './src') } ]
|
|
92
|
+
array_entries = re.findall(
|
|
93
|
+
r"""find\s*:\s*['"]([^'"]+)['"][\s\S]*?replacement\s*:\s*(?:(?:path\.)?resolve\([^)]*['"]([^'"]+)['"]\)|['"]([^'"]+)['"])""",
|
|
94
|
+
content,
|
|
95
|
+
)
|
|
96
|
+
for key, target1, target2 in array_entries:
|
|
97
|
+
raw_target = (target1 or target2 or "").strip().replace("\\", "/").lstrip("./")
|
|
98
|
+
if raw_target:
|
|
99
|
+
clean_key = key.rstrip("/")
|
|
100
|
+
parsed_paths[f"{clean_key}/*"] = (f"{raw_target}/*",)
|
|
101
|
+
parsed_paths[clean_key] = (raw_target,)
|
|
102
|
+
|
|
103
|
+
if not parsed_paths:
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
base_dir_path = file_path.parent
|
|
107
|
+
rel_base_dir = posixpath.normpath(base_dir_path.relative_to(repo_root).as_posix())
|
|
108
|
+
if rel_base_dir == ".":
|
|
109
|
+
rel_base_dir = ""
|
|
110
|
+
|
|
111
|
+
return TsConfig(
|
|
112
|
+
config_path=posixpath.normpath(file_path.relative_to(repo_root).as_posix()),
|
|
113
|
+
base_dir=rel_base_dir,
|
|
114
|
+
base_url=".",
|
|
115
|
+
paths=parsed_paths,
|
|
116
|
+
)
|
|
117
|
+
except Exception:
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def _parse_single_config(file_path: Path, repo_root: Path) -> TsConfig | None:
|
|
122
|
+
try:
|
|
123
|
+
raw = file_path.read_text(encoding="utf-8", errors="replace")
|
|
124
|
+
cleaned = strip_json_comments(raw)
|
|
125
|
+
data = json.loads(cleaned)
|
|
126
|
+
compiler_opts = data.get("compilerOptions", {})
|
|
127
|
+
|
|
128
|
+
base_dir_path = file_path.parent
|
|
129
|
+
rel_base_dir = posixpath.normpath(base_dir_path.relative_to(repo_root).as_posix())
|
|
130
|
+
if rel_base_dir == ".":
|
|
131
|
+
rel_base_dir = ""
|
|
132
|
+
|
|
133
|
+
base_url = compiler_opts.get("baseUrl", ".")
|
|
134
|
+
raw_paths = compiler_opts.get("paths", {})
|
|
135
|
+
|
|
136
|
+
parsed_paths: dict[str, tuple[str, ...]] = {}
|
|
137
|
+
for pattern, targets in raw_paths.items():
|
|
138
|
+
if isinstance(targets, list):
|
|
139
|
+
parsed_paths[pattern] = tuple(str(t) for t in targets)
|
|
140
|
+
elif isinstance(targets, str):
|
|
141
|
+
parsed_paths[pattern] = (targets,)
|
|
142
|
+
|
|
143
|
+
if not parsed_paths and base_url in (".", ""):
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
return TsConfig(
|
|
147
|
+
config_path=posixpath.normpath(file_path.relative_to(repo_root).as_posix()),
|
|
148
|
+
base_dir=rel_base_dir,
|
|
149
|
+
base_url=base_url,
|
|
150
|
+
paths=parsed_paths,
|
|
151
|
+
)
|
|
152
|
+
except Exception:
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
def resolve_alias(
|
|
156
|
+
self,
|
|
157
|
+
imported_module: str,
|
|
158
|
+
source_file: str,
|
|
159
|
+
known_files: set[str],
|
|
160
|
+
) -> str | None:
|
|
161
|
+
"""Resolve an aliased module (e.g. '@/components/Button') to a file path in known_files."""
|
|
162
|
+
if not imported_module or imported_module.startswith("."):
|
|
163
|
+
return None
|
|
164
|
+
|
|
165
|
+
clean_src = source_file.replace("\\", "/").lstrip("./")
|
|
166
|
+
|
|
167
|
+
# Pick matching config: deepest base_dir matching source_file, or fallback to root config
|
|
168
|
+
chosen_config: TsConfig | None = None
|
|
169
|
+
for cfg in self.configs:
|
|
170
|
+
if not cfg.base_dir or clean_src.startswith(f"{cfg.base_dir}/"):
|
|
171
|
+
chosen_config = cfg
|
|
172
|
+
break
|
|
173
|
+
if not chosen_config and self.configs:
|
|
174
|
+
chosen_config = self.configs[-1]
|
|
175
|
+
|
|
176
|
+
if not chosen_config:
|
|
177
|
+
return None
|
|
178
|
+
|
|
179
|
+
# Check paths mappings
|
|
180
|
+
for pattern, targets in chosen_config.paths.items():
|
|
181
|
+
if "*" in pattern:
|
|
182
|
+
star_idx = pattern.index("*")
|
|
183
|
+
prefix = pattern[:star_idx]
|
|
184
|
+
suffix = pattern[star_idx + 1:]
|
|
185
|
+
if imported_module.startswith(prefix) and (not suffix or imported_module.endswith(suffix)):
|
|
186
|
+
wildcard = imported_module[len(prefix):len(imported_module) - len(suffix) if suffix else None]
|
|
187
|
+
for target_tmpl in targets:
|
|
188
|
+
target = target_tmpl.replace("*", wildcard)
|
|
189
|
+
resolved = self._test_target(
|
|
190
|
+
chosen_config.base_dir, chosen_config.base_url, target, known_files
|
|
191
|
+
)
|
|
192
|
+
if resolved:
|
|
193
|
+
return resolved
|
|
194
|
+
else:
|
|
195
|
+
# Exact match pattern (e.g. "@lib": ["src/lib"])
|
|
196
|
+
if imported_module == pattern:
|
|
197
|
+
for target in targets:
|
|
198
|
+
resolved = self._test_target(
|
|
199
|
+
chosen_config.base_dir, chosen_config.base_url, target, known_files
|
|
200
|
+
)
|
|
201
|
+
if resolved:
|
|
202
|
+
return resolved
|
|
203
|
+
|
|
204
|
+
# Fallback to baseUrl-relative imports if baseUrl is configured
|
|
205
|
+
if chosen_config.base_url and chosen_config.base_url not in (".", ""):
|
|
206
|
+
resolved = self._test_target(
|
|
207
|
+
chosen_config.base_dir, chosen_config.base_url, imported_module, known_files
|
|
208
|
+
)
|
|
209
|
+
if resolved:
|
|
210
|
+
return resolved
|
|
211
|
+
|
|
212
|
+
return None
|
|
213
|
+
|
|
214
|
+
@staticmethod
|
|
215
|
+
def _test_target(
|
|
216
|
+
base_dir: str,
|
|
217
|
+
base_url: str,
|
|
218
|
+
target_path: str,
|
|
219
|
+
known_files: set[str],
|
|
220
|
+
) -> str | None:
|
|
221
|
+
"""Check candidate target path against known repository files with extensions and index files."""
|
|
222
|
+
# Join base_dir, base_url, and target_path in posix style
|
|
223
|
+
parts = [p for p in (base_dir, base_url, target_path) if p and p not in (".", "")]
|
|
224
|
+
base = posixpath.normpath("/".join(parts)).lstrip("./")
|
|
225
|
+
|
|
226
|
+
candidates = [base]
|
|
227
|
+
for ext in (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".css", ".scss"):
|
|
228
|
+
candidates.append(f"{base}{ext}")
|
|
229
|
+
for idx in ("index.ts", "index.tsx", "index.js", "index.jsx"):
|
|
230
|
+
candidates.append(posixpath.join(base, idx))
|
|
231
|
+
|
|
232
|
+
for cand in candidates:
|
|
233
|
+
cand_norm = cand.lstrip("./")
|
|
234
|
+
if cand_norm in known_files:
|
|
235
|
+
return cand_norm
|
|
236
|
+
return None
|