repodna-engine 1.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.
- repodna/__init__.py +3 -0
- repodna/__main__.py +10 -0
- repodna/advisor/__init__.py +17 -0
- repodna/advisor/engine.py +502 -0
- repodna/advisor/models.py +101 -0
- repodna/agent/__init__.py +87 -0
- repodna/agent/context.py +558 -0
- repodna/agent/deltas.py +198 -0
- repodna/agent/evidence.py +134 -0
- repodna/agent/expansion.py +447 -0
- repodna/agent/localization.py +518 -0
- repodna/agent/models.py +695 -0
- repodna/agent/patch.py +378 -0
- repodna/agent/postflight.py +278 -0
- repodna/agent/preflight.py +336 -0
- repodna/agent/ranking.py +318 -0
- repodna/agent/repo_map.py +392 -0
- repodna/agent/safety.py +111 -0
- repodna/agent/service.py +574 -0
- repodna/agent/sessions.py +264 -0
- repodna/agent/task.py +660 -0
- repodna/agent/telemetry.py +101 -0
- repodna/agent/token_budget.py +231 -0
- repodna/api/__init__.py +1 -0
- repodna/api/agent_routes.py +248 -0
- repodna/api/app.py +2904 -0
- repodna/benchmarks/__init__.py +29 -0
- repodna/benchmarks/baselines.py +126 -0
- repodna/benchmarks/budget_bench.py +162 -0
- repodna/benchmarks/engine.py +418 -0
- repodna/benchmarks/evaluator.py +310 -0
- repodna/benchmarks/metrics.py +206 -0
- repodna/benchmarks/models.py +194 -0
- repodna/benchmarks/scalability.py +166 -0
- repodna/brain/__init__.py +46 -0
- repodna/brain/evidence.py +276 -0
- repodna/brain/extractor.py +1207 -0
- repodna/brain/indexer.py +766 -0
- repodna/brain/models.py +275 -0
- repodna/brain/multilang_extractors.py +889 -0
- repodna/brain/retrieval.py +469 -0
- repodna/brain/tracer.py +203 -0
- repodna/cli/__init__.py +1 -0
- repodna/cli/__main__.py +10 -0
- repodna/cli/agent_cmd.py +228 -0
- repodna/cli/installer.py +590 -0
- repodna/cli/main.py +2173 -0
- repodna/cli/plugin_cmd.py +130 -0
- repodna/cli/workspace_cmd.py +211 -0
- repodna/context/__init__.py +9 -0
- repodna/context/builder.py +379 -0
- repodna/context/models.py +133 -0
- repodna/contract/__init__.py +39 -0
- repodna/contract/evaluator.py +318 -0
- repodna/contract/loader.py +260 -0
- repodna/contract/models.py +185 -0
- repodna/core/__init__.py +1 -0
- repodna/core/analyzer.py +1424 -0
- repodna/diff/__init__.py +35 -0
- repodna/diff/engine.py +332 -0
- repodna/diff/models.py +117 -0
- repodna/diff/snapshot.py +248 -0
- repodna/ecosystem/__init__.py +27 -0
- repodna/ecosystem/contracts.py +129 -0
- repodna/ecosystem/doctor.py +253 -0
- repodna/git_insights/__init__.py +1 -0
- repodna/git_insights/analyzer.py +273 -0
- repodna/graph/__init__.py +1 -0
- repodna/graph/engine.py +562 -0
- repodna/guardian/__init__.py +17 -0
- repodna/guardian/engine.py +369 -0
- repodna/guardian/models.py +104 -0
- repodna/history/__init__.py +40 -0
- repodna/history/cache.py +240 -0
- repodna/history/diff.py +394 -0
- repodna/history/engine.py +557 -0
- repodna/history/evidence.py +160 -0
- repodna/history/models.py +258 -0
- repodna/history/timeline.py +164 -0
- repodna/intelligence/__init__.py +33 -0
- repodna/intelligence/models.py +165 -0
- repodna/intelligence/service.py +570 -0
- repodna/live/__init__.py +94 -0
- repodna/live/alerts.py +443 -0
- repodna/live/coordinator.py +351 -0
- repodna/live/diff.py +444 -0
- repodna/live/events.py +471 -0
- repodna/live/filtering.py +329 -0
- repodna/live/history.py +637 -0
- repodna/live/models.py +505 -0
- repodna/live/observer.py +653 -0
- repodna/live/reconciliation.py +253 -0
- repodna/live/session.py +1547 -0
- repodna/mcp/__init__.py +5 -0
- repodna/mcp/__main__.py +6 -0
- repodna/mcp/agent_tools.py +258 -0
- repodna/mcp/server.py +3283 -0
- repodna/mcp/workspace_tools.py +200 -0
- repodna/parsers/__init__.py +13 -0
- repodna/parsers/base.py +126 -0
- repodna/parsers/capabilities.py +361 -0
- repodna/parsers/project_metadata.py +232 -0
- repodna/parsers/resolver.py +621 -0
- repodna/parsers/treesitter_parser.py +830 -0
- repodna/passport/__init__.py +64 -0
- repodna/passport/generator.py +546 -0
- repodna/passport/migrator.py +139 -0
- repodna/passport/models.py +224 -0
- repodna/passport/validator.py +143 -0
- repodna/performance/__init__.py +89 -0
- repodna/performance/cache.py +1584 -0
- repodna/performance/identity.py +341 -0
- repodna/performance/incremental.py +317 -0
- repodna/performance/models.py +157 -0
- repodna/performance/parallel.py +291 -0
- repodna/plugins/__init__.py +47 -0
- repodna/plugins/evaluator.py +334 -0
- repodna/plugins/models.py +113 -0
- repodna/plugins/validator.py +256 -0
- repodna/quality/__init__.py +91 -0
- repodna/quality/complexity.py +352 -0
- repodna/quality/config.py +159 -0
- repodna/quality/debt.py +73 -0
- repodna/quality/duplicates.py +330 -0
- repodna/quality/engine.py +282 -0
- repodna/quality/impact.py +198 -0
- repodna/quality/models.py +427 -0
- repodna/quality/rules.py +364 -0
- repodna/quality/sarif.py +107 -0
- repodna/quality/security_signals.py +278 -0
- repodna/quality/test_mapping.py +271 -0
- repodna/quality/unused.py +201 -0
- repodna/reports/__init__.py +1 -0
- repodna/reports/exporter.py +374 -0
- repodna/rules/__init__.py +1 -0
- repodna/rules/health.py +436 -0
- repodna/schemas/__init__.py +1 -0
- repodna/schemas/models.py +348 -0
- repodna/security/__init__.py +1 -0
- repodna/security/safe_yaml.py +81 -0
- repodna/security/validators.py +583 -0
- repodna/skills/__init__.py +0 -0
- repodna/skills/repodna/SKILL.md +59 -0
- repodna/skills/repodna/__init__.py +0 -0
- repodna/skills/repodna/examples/workflows.md +85 -0
- repodna/skills/repodna/references/architecture-rules.md +26 -0
- repodna/storage/__init__.py +1 -0
- repodna/storage/workspace.py +199 -0
- repodna/webui/__init__.py +1 -0
- repodna/webui/assets/DependencyGraph-km_Qo-nG.js +43 -0
- repodna/webui/assets/HealthReportView-WVL39aNO.js +1 -0
- repodna/webui/assets/index-ByZ5e5pe.js +506 -0
- repodna/webui/assets/index-CDj3e8hw.css +1 -0
- repodna/webui/index.html +21 -0
- repodna/workspace/__init__.py +131 -0
- repodna/workspace/compatibility.py +317 -0
- repodna/workspace/context.py +175 -0
- repodna/workspace/contracts.py +369 -0
- repodna/workspace/federation.py +411 -0
- repodna/workspace/identity.py +202 -0
- repodna/workspace/impact.py +111 -0
- repodna/workspace/manifest.py +266 -0
- repodna/workspace/models.py +461 -0
- repodna/workspace/packages.py +494 -0
- repodna/workspace/policies.py +142 -0
- repodna/workspace/services.py +238 -0
- repodna/workspace/topology.py +316 -0
- repodna_engine-1.0.1.dist-info/METADATA +129 -0
- repodna_engine-1.0.1.dist-info/RECORD +173 -0
- repodna_engine-1.0.1.dist-info/WHEEL +5 -0
- repodna_engine-1.0.1.dist-info/entry_points.txt +2 -0
- repodna_engine-1.0.1.dist-info/licenses/LICENSE +21 -0
- repodna_engine-1.0.1.dist-info/top_level.txt +1 -0
repodna/diff/__init__.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""RepoDNA Architecture Diff Engine."""
|
|
2
|
+
|
|
3
|
+
from repodna.diff.engine import ArchitectureDiffEngine
|
|
4
|
+
from repodna.diff.models import (
|
|
5
|
+
ArchitectureDiffResult,
|
|
6
|
+
CouplingDeltaItem,
|
|
7
|
+
CoverageDelta,
|
|
8
|
+
CycleChanges,
|
|
9
|
+
CycleDiffItem,
|
|
10
|
+
DependencyChanges,
|
|
11
|
+
EdgeDiffItem,
|
|
12
|
+
HealthScoreDelta,
|
|
13
|
+
ModuleChanges,
|
|
14
|
+
RenamedModule,
|
|
15
|
+
RevisionProvenance,
|
|
16
|
+
RuleFindingChanges,
|
|
17
|
+
)
|
|
18
|
+
from repodna.diff.snapshot import SnapshotManager
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ArchitectureDiffEngine",
|
|
22
|
+
"ArchitectureDiffResult",
|
|
23
|
+
"CouplingDeltaItem",
|
|
24
|
+
"CoverageDelta",
|
|
25
|
+
"CycleChanges",
|
|
26
|
+
"CycleDiffItem",
|
|
27
|
+
"DependencyChanges",
|
|
28
|
+
"EdgeDiffItem",
|
|
29
|
+
"HealthScoreDelta",
|
|
30
|
+
"ModuleChanges",
|
|
31
|
+
"RenamedModule",
|
|
32
|
+
"RevisionProvenance",
|
|
33
|
+
"RuleFindingChanges",
|
|
34
|
+
"SnapshotManager",
|
|
35
|
+
]
|
repodna/diff/engine.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"""Architecture Diff Engine for comparing two immutable repository analysis snapshots."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
|
|
7
|
+
from repodna.diff.models import (
|
|
8
|
+
ArchitectureDiffResult,
|
|
9
|
+
CouplingDeltaItem,
|
|
10
|
+
CoverageDelta,
|
|
11
|
+
CycleChanges,
|
|
12
|
+
CycleDiffItem,
|
|
13
|
+
DependencyChanges,
|
|
14
|
+
EdgeDiffItem,
|
|
15
|
+
HealthScoreDelta,
|
|
16
|
+
ModuleChanges,
|
|
17
|
+
RenamedModule,
|
|
18
|
+
RevisionProvenance,
|
|
19
|
+
RuleFindingChanges,
|
|
20
|
+
)
|
|
21
|
+
from repodna.schemas.models import AnalysisResult, FileNode
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _canonicalize_cycle(nodes: list[str]) -> tuple[str, ...]:
|
|
25
|
+
"""Canonicalize a cycle path [A, B, C, A] to a rotation-invariant representation."""
|
|
26
|
+
cleaned = [n for n in nodes]
|
|
27
|
+
if len(cleaned) > 1 and cleaned[0] == cleaned[-1]:
|
|
28
|
+
cleaned = cleaned[:-1]
|
|
29
|
+
if not cleaned:
|
|
30
|
+
return ()
|
|
31
|
+
# Find lexicographically smallest rotation
|
|
32
|
+
rotations = [tuple(cleaned[i:] + cleaned[:i]) for i in range(len(cleaned))]
|
|
33
|
+
return min(rotations)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ArchitectureDiffEngine:
|
|
37
|
+
"""Computes architectural deltas between two analysis snapshots."""
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def compare_analyses(
|
|
41
|
+
base: AnalysisResult,
|
|
42
|
+
head: AnalysisResult,
|
|
43
|
+
base_ref: str = "base",
|
|
44
|
+
head_ref: str = "head",
|
|
45
|
+
base_commit_sha: str | None = None,
|
|
46
|
+
head_commit_sha: str | None = None,
|
|
47
|
+
base_is_working_tree: bool = False,
|
|
48
|
+
head_is_working_tree: bool = False,
|
|
49
|
+
git_renames: dict[str, str] | None = None,
|
|
50
|
+
) -> ArchitectureDiffResult:
|
|
51
|
+
base_files: dict[str, FileNode] = {f.id: f for f in base.files}
|
|
52
|
+
head_files: dict[str, FileNode] = {f.id: f for f in head.files}
|
|
53
|
+
|
|
54
|
+
base_ids = set(base_files.keys())
|
|
55
|
+
head_ids = set(head_files.keys())
|
|
56
|
+
|
|
57
|
+
raw_added = head_ids - base_ids
|
|
58
|
+
raw_removed = base_ids - head_ids
|
|
59
|
+
|
|
60
|
+
# Check for coverage/skip caveats
|
|
61
|
+
head_skipped_paths = {s.path for s in head.transparency.skipped_files}
|
|
62
|
+
caveats: list[str] = []
|
|
63
|
+
|
|
64
|
+
apparent_removed = set()
|
|
65
|
+
for r_id in raw_removed:
|
|
66
|
+
if r_id in head_skipped_paths:
|
|
67
|
+
caveats.append(
|
|
68
|
+
f"Module '{r_id}' was excluded by resource/file limits in '{head_ref}' rather than deleted."
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
apparent_removed.add(r_id)
|
|
72
|
+
|
|
73
|
+
renamed: list[RenamedModule] = []
|
|
74
|
+
confirmed_added: list[str] = []
|
|
75
|
+
confirmed_removed: list[str] = sorted(apparent_removed)
|
|
76
|
+
|
|
77
|
+
# 1. First process Git-verified renames (from git diff -M)
|
|
78
|
+
if git_renames:
|
|
79
|
+
for old_p, new_p in git_renames.items():
|
|
80
|
+
if old_p in confirmed_removed and new_p in raw_added:
|
|
81
|
+
renamed.append(
|
|
82
|
+
RenamedModule(
|
|
83
|
+
old_path=old_p,
|
|
84
|
+
new_path=new_p,
|
|
85
|
+
confidence=1.0,
|
|
86
|
+
reason="Verified by Git history rename detection",
|
|
87
|
+
is_verified_by_git=True,
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
confirmed_removed.remove(old_p)
|
|
91
|
+
raw_added.remove(new_p)
|
|
92
|
+
|
|
93
|
+
# 2. Heuristic rename detection for remaining additions/removals
|
|
94
|
+
for a_id in sorted(raw_added):
|
|
95
|
+
a_node = head_files[a_id]
|
|
96
|
+
match_found = False
|
|
97
|
+
for r_id in list(confirmed_removed):
|
|
98
|
+
r_node = base_files[r_id]
|
|
99
|
+
# Same basename and same language
|
|
100
|
+
if a_node.name == r_node.name and a_node.language == r_node.language:
|
|
101
|
+
# Check symbol overlap
|
|
102
|
+
a_syms = {s.name for s in a_node.symbols}
|
|
103
|
+
r_syms = {s.name for s in r_node.symbols}
|
|
104
|
+
sym_overlap = len(a_syms & r_syms) if (a_syms and r_syms) else 0
|
|
105
|
+
|
|
106
|
+
if sym_overlap > 0 or (not a_syms and not r_syms and abs(a_node.lines_code - r_node.lines_code) < 10):
|
|
107
|
+
renamed.append(
|
|
108
|
+
RenamedModule(
|
|
109
|
+
old_path=r_id,
|
|
110
|
+
new_path=a_id,
|
|
111
|
+
confidence=0.85 if sym_overlap > 0 else 0.70,
|
|
112
|
+
reason=f"Heuristic match: basename '{a_node.name}' with matching language and {sym_overlap} shared symbol(s)",
|
|
113
|
+
is_verified_by_git=False,
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
confirmed_removed.remove(r_id)
|
|
117
|
+
match_found = True
|
|
118
|
+
break
|
|
119
|
+
if not match_found:
|
|
120
|
+
confirmed_added.append(a_id)
|
|
121
|
+
|
|
122
|
+
# Dependencies
|
|
123
|
+
base_edges = {(e.source, e.target): e for e in base.edges}
|
|
124
|
+
head_edges = {(e.source, e.target): e for e in head.edges}
|
|
125
|
+
|
|
126
|
+
added_edges = [
|
|
127
|
+
EdgeDiffItem(source=src, target=tgt, import_names=e.import_names)
|
|
128
|
+
for (src, tgt), e in head_edges.items()
|
|
129
|
+
if (src, tgt) not in base_edges
|
|
130
|
+
]
|
|
131
|
+
removed_edges = [
|
|
132
|
+
EdgeDiffItem(source=src, target=tgt, import_names=e.import_names)
|
|
133
|
+
for (src, tgt), e in base_edges.items()
|
|
134
|
+
if (src, tgt) not in head_edges
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
# Cycles
|
|
138
|
+
base_canonical_cycles = {
|
|
139
|
+
_canonicalize_cycle(c.nodes): c for c in base.cycles
|
|
140
|
+
}
|
|
141
|
+
head_canonical_cycles = {
|
|
142
|
+
_canonicalize_cycle(c.nodes): c for c in head.cycles
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
new_cycles = [
|
|
146
|
+
CycleDiffItem(
|
|
147
|
+
id=c.id,
|
|
148
|
+
nodes=c.nodes,
|
|
149
|
+
length=c.length,
|
|
150
|
+
severity=c.severity,
|
|
151
|
+
description=c.description,
|
|
152
|
+
)
|
|
153
|
+
for key, c in head_canonical_cycles.items()
|
|
154
|
+
if key not in base_canonical_cycles
|
|
155
|
+
]
|
|
156
|
+
resolved_cycles = [
|
|
157
|
+
CycleDiffItem(
|
|
158
|
+
id=c.id,
|
|
159
|
+
nodes=c.nodes,
|
|
160
|
+
length=c.length,
|
|
161
|
+
severity=c.severity,
|
|
162
|
+
description=c.description,
|
|
163
|
+
)
|
|
164
|
+
for key, c in base_canonical_cycles.items()
|
|
165
|
+
if key not in head_canonical_cycles
|
|
166
|
+
]
|
|
167
|
+
persisting_cycles_count = len(head_canonical_cycles) - len(new_cycles)
|
|
168
|
+
|
|
169
|
+
# Significant coupling deltas
|
|
170
|
+
coupling_deltas: list[CouplingDeltaItem] = []
|
|
171
|
+
for fid in sorted(base_ids & head_ids):
|
|
172
|
+
b_n = base_files[fid]
|
|
173
|
+
h_n = head_files[fid]
|
|
174
|
+
fan_in_delta = h_n.fan_in - b_n.fan_in
|
|
175
|
+
fan_out_delta = h_n.fan_out - b_n.fan_out
|
|
176
|
+
inst_delta = round(h_n.instability - b_n.instability, 3)
|
|
177
|
+
|
|
178
|
+
if abs(fan_in_delta) >= 2 or abs(fan_out_delta) >= 2 or abs(inst_delta) >= 0.15:
|
|
179
|
+
coupling_deltas.append(
|
|
180
|
+
CouplingDeltaItem(
|
|
181
|
+
file_id=fid,
|
|
182
|
+
fan_in_before=b_n.fan_in,
|
|
183
|
+
fan_in_after=h_n.fan_in,
|
|
184
|
+
fan_in_delta=fan_in_delta,
|
|
185
|
+
fan_out_before=b_n.fan_out,
|
|
186
|
+
fan_out_after=h_n.fan_out,
|
|
187
|
+
fan_out_delta=fan_out_delta,
|
|
188
|
+
instability_before=b_n.instability,
|
|
189
|
+
instability_after=h_n.instability,
|
|
190
|
+
instability_delta=inst_delta,
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# Health score delta
|
|
195
|
+
b_hr = base.health_report
|
|
196
|
+
h_hr = head.health_report
|
|
197
|
+
score_delta = None
|
|
198
|
+
if b_hr.overall_score is not None and h_hr.overall_score is not None:
|
|
199
|
+
score_delta = round(h_hr.overall_score - b_hr.overall_score, 2)
|
|
200
|
+
|
|
201
|
+
health_delta = HealthScoreDelta(
|
|
202
|
+
score_before=b_hr.overall_score,
|
|
203
|
+
score_after=h_hr.overall_score,
|
|
204
|
+
score_delta=score_delta,
|
|
205
|
+
grade_before=b_hr.grade,
|
|
206
|
+
grade_after=h_hr.grade,
|
|
207
|
+
status_before=b_hr.status,
|
|
208
|
+
status_after=h_hr.status,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
# Rule findings delta
|
|
212
|
+
base_findings_map = {f.rule_id + "::" + ":".join(sorted(f.affected_files)): f for f in b_hr.findings}
|
|
213
|
+
head_findings_map = {f.rule_id + "::" + ":".join(sorted(f.affected_files)): f for f in h_hr.findings}
|
|
214
|
+
|
|
215
|
+
new_findings = [f for k, f in head_findings_map.items() if k not in base_findings_map]
|
|
216
|
+
resolved_findings = [f for k, f in base_findings_map.items() if k not in head_findings_map]
|
|
217
|
+
persisting_count = len(head_findings_map) - len(new_findings)
|
|
218
|
+
|
|
219
|
+
# Coverage delta
|
|
220
|
+
b_tr = base.transparency
|
|
221
|
+
h_tr = head.transparency
|
|
222
|
+
loc_cov_delta = round(h_tr.ast_loc_coverage_pct - b_tr.ast_loc_coverage_pct, 2)
|
|
223
|
+
|
|
224
|
+
if b_tr.supported_languages_detected != h_tr.supported_languages_detected:
|
|
225
|
+
caveats.append(
|
|
226
|
+
f"Supported language set shifted between revisions: "
|
|
227
|
+
f"'{b_tr.supported_languages_detected}' -> '{h_tr.supported_languages_detected}'."
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
coverage_delta = CoverageDelta(
|
|
231
|
+
ast_loc_coverage_before=b_tr.ast_loc_coverage_pct,
|
|
232
|
+
ast_loc_coverage_after=h_tr.ast_loc_coverage_pct,
|
|
233
|
+
ast_loc_coverage_delta=loc_cov_delta,
|
|
234
|
+
supported_langs_before=b_tr.supported_languages_detected,
|
|
235
|
+
supported_langs_after=h_tr.supported_languages_detected,
|
|
236
|
+
caveats=caveats,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
# Verdict
|
|
240
|
+
if new_cycles:
|
|
241
|
+
verdict = "regressive_cycles"
|
|
242
|
+
elif score_delta is not None and score_delta < -3.0:
|
|
243
|
+
verdict = "degraded"
|
|
244
|
+
elif (score_delta is not None and score_delta > 3.0) or (resolved_cycles and not new_cycles):
|
|
245
|
+
verdict = "improved"
|
|
246
|
+
else:
|
|
247
|
+
verdict = "neutral"
|
|
248
|
+
|
|
249
|
+
# Summary text
|
|
250
|
+
summary_lines = [
|
|
251
|
+
f"RepoDNA Architecture Diff: {base_ref} -> {head_ref}",
|
|
252
|
+
f"Verdict: {verdict.upper()}",
|
|
253
|
+
f"Modules: +{len(confirmed_added)} added, -{len(confirmed_removed)} removed, {len(renamed)} renamed.",
|
|
254
|
+
f"Dependencies: +{len(added_edges)} added edges, -{len(removed_edges)} removed edges.",
|
|
255
|
+
f"Cycles: +{len(new_cycles)} new cycles, -{len(resolved_cycles)} resolved ({persisting_cycles_count} persistent).",
|
|
256
|
+
]
|
|
257
|
+
if score_delta is not None:
|
|
258
|
+
sign = "+" if score_delta >= 0 else ""
|
|
259
|
+
summary_lines.append(
|
|
260
|
+
f"Health Score: {b_hr.overall_score:.1f} ({b_hr.grade}) -> {h_hr.overall_score:.1f} ({h_hr.grade}) [{sign}{score_delta:.1f} pts]"
|
|
261
|
+
)
|
|
262
|
+
else:
|
|
263
|
+
summary_lines.append(f"Health Status: {b_hr.status} -> {h_hr.status}")
|
|
264
|
+
|
|
265
|
+
if new_findings:
|
|
266
|
+
new_lines = []
|
|
267
|
+
for f in new_findings[:4]:
|
|
268
|
+
files_str = ", ".join(f.affected_files[:2])
|
|
269
|
+
new_lines.append(f"{f.rule_id} in [{files_str}]")
|
|
270
|
+
summary_lines.append(f"New Architectural Violations ({len(new_findings)}): {'; '.join(new_lines)}")
|
|
271
|
+
if resolved_findings:
|
|
272
|
+
res_lines = []
|
|
273
|
+
for f in resolved_findings[:4]:
|
|
274
|
+
files_str = ", ".join(f.affected_files[:2])
|
|
275
|
+
res_lines.append(f"{f.rule_id} in [{files_str}]")
|
|
276
|
+
summary_lines.append(f"Resolved Violations ({len(resolved_findings)}): {'; '.join(res_lines)}")
|
|
277
|
+
if caveats:
|
|
278
|
+
summary_lines.append(f"Coverage Caveats: {'; '.join(caveats)}")
|
|
279
|
+
|
|
280
|
+
base_prov = RevisionProvenance(
|
|
281
|
+
ref_name=base_ref,
|
|
282
|
+
commit_sha=base_commit_sha,
|
|
283
|
+
is_working_tree=base_is_working_tree,
|
|
284
|
+
analyzed_at=base.analyzed_at,
|
|
285
|
+
total_files=base.total_files,
|
|
286
|
+
total_lines_code=base.total_lines_code,
|
|
287
|
+
ast_coverage_pct=b_tr.ast_loc_coverage_pct,
|
|
288
|
+
health_score=b_hr.overall_score,
|
|
289
|
+
health_grade=b_hr.grade,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
head_prov = RevisionProvenance(
|
|
293
|
+
ref_name=head_ref,
|
|
294
|
+
commit_sha=head_commit_sha,
|
|
295
|
+
is_working_tree=head_is_working_tree,
|
|
296
|
+
analyzed_at=head.analyzed_at,
|
|
297
|
+
total_files=head.total_files,
|
|
298
|
+
total_lines_code=head.total_lines_code,
|
|
299
|
+
ast_coverage_pct=h_tr.ast_loc_coverage_pct,
|
|
300
|
+
health_score=h_hr.overall_score,
|
|
301
|
+
health_grade=h_hr.grade,
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
return ArchitectureDiffResult(
|
|
305
|
+
base_provenance=base_prov,
|
|
306
|
+
head_provenance=head_prov,
|
|
307
|
+
generated_at=datetime.now(UTC),
|
|
308
|
+
verdict=verdict,
|
|
309
|
+
module_changes=ModuleChanges(
|
|
310
|
+
added=confirmed_added,
|
|
311
|
+
removed=confirmed_removed,
|
|
312
|
+
renamed=renamed,
|
|
313
|
+
),
|
|
314
|
+
dependency_changes=DependencyChanges(
|
|
315
|
+
added_edges=added_edges,
|
|
316
|
+
removed_edges=removed_edges,
|
|
317
|
+
),
|
|
318
|
+
cycle_changes=CycleChanges(
|
|
319
|
+
new_cycles=new_cycles,
|
|
320
|
+
resolved_cycles=resolved_cycles,
|
|
321
|
+
persisting_cycles=persisting_cycles_count,
|
|
322
|
+
),
|
|
323
|
+
significant_coupling_deltas=coupling_deltas,
|
|
324
|
+
health_delta=health_delta,
|
|
325
|
+
finding_changes=RuleFindingChanges(
|
|
326
|
+
new_findings=new_findings,
|
|
327
|
+
resolved_findings=resolved_findings,
|
|
328
|
+
persisting_findings_count=persisting_count,
|
|
329
|
+
),
|
|
330
|
+
coverage_delta=coverage_delta,
|
|
331
|
+
summary_text="\n".join(summary_lines),
|
|
332
|
+
)
|
repodna/diff/models.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Typed Pydantic schemas for the RepoDNA Architecture Diff Engine."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
from repodna.schemas.models import RuleFinding, SeverityLevel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RevisionProvenance(BaseModel):
|
|
13
|
+
ref_name: str
|
|
14
|
+
commit_sha: str | None = None
|
|
15
|
+
commit_date: str | None = None
|
|
16
|
+
commit_author: str | None = None
|
|
17
|
+
is_working_tree: bool = False
|
|
18
|
+
analyzed_at: datetime
|
|
19
|
+
analysis_version: str = "0.3.0"
|
|
20
|
+
total_files: int
|
|
21
|
+
total_lines_code: int
|
|
22
|
+
ast_coverage_pct: float
|
|
23
|
+
health_score: float | None = None
|
|
24
|
+
health_grade: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RenamedModule(BaseModel):
|
|
28
|
+
old_path: str
|
|
29
|
+
new_path: str
|
|
30
|
+
confidence: float
|
|
31
|
+
reason: str
|
|
32
|
+
is_verified_by_git: bool = False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ModuleChanges(BaseModel):
|
|
36
|
+
added: list[str] = Field(default_factory=list)
|
|
37
|
+
removed: list[str] = Field(default_factory=list)
|
|
38
|
+
renamed: list[RenamedModule] = Field(default_factory=list)
|
|
39
|
+
modified_dependencies: list[str] = Field(default_factory=list)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class EdgeDiffItem(BaseModel):
|
|
43
|
+
source: str
|
|
44
|
+
target: str
|
|
45
|
+
import_names: list[str] = Field(default_factory=list)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class DependencyChanges(BaseModel):
|
|
49
|
+
added_edges: list[EdgeDiffItem] = Field(default_factory=list)
|
|
50
|
+
removed_edges: list[EdgeDiffItem] = Field(default_factory=list)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class CycleDiffItem(BaseModel):
|
|
54
|
+
id: str
|
|
55
|
+
nodes: list[str]
|
|
56
|
+
length: int
|
|
57
|
+
severity: SeverityLevel
|
|
58
|
+
description: str
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class CycleChanges(BaseModel):
|
|
62
|
+
new_cycles: list[CycleDiffItem] = Field(default_factory=list)
|
|
63
|
+
resolved_cycles: list[CycleDiffItem] = Field(default_factory=list)
|
|
64
|
+
persisting_cycles: int = 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class CouplingDeltaItem(BaseModel):
|
|
68
|
+
file_id: str
|
|
69
|
+
fan_in_before: int
|
|
70
|
+
fan_in_after: int
|
|
71
|
+
fan_in_delta: int
|
|
72
|
+
fan_out_before: int
|
|
73
|
+
fan_out_after: int
|
|
74
|
+
fan_out_delta: int
|
|
75
|
+
instability_before: float
|
|
76
|
+
instability_after: float
|
|
77
|
+
instability_delta: float
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class HealthScoreDelta(BaseModel):
|
|
81
|
+
score_before: float | None = None
|
|
82
|
+
score_after: float | None = None
|
|
83
|
+
score_delta: float | None = None
|
|
84
|
+
grade_before: str
|
|
85
|
+
grade_after: str
|
|
86
|
+
status_before: str
|
|
87
|
+
status_after: str
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class RuleFindingChanges(BaseModel):
|
|
91
|
+
new_findings: list[RuleFinding] = Field(default_factory=list)
|
|
92
|
+
resolved_findings: list[RuleFinding] = Field(default_factory=list)
|
|
93
|
+
persisting_findings_count: int = 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class CoverageDelta(BaseModel):
|
|
97
|
+
ast_loc_coverage_before: float
|
|
98
|
+
ast_loc_coverage_after: float
|
|
99
|
+
ast_loc_coverage_delta: float
|
|
100
|
+
supported_langs_before: list[str]
|
|
101
|
+
supported_langs_after: list[str]
|
|
102
|
+
caveats: list[str] = Field(default_factory=list)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class ArchitectureDiffResult(BaseModel):
|
|
106
|
+
base_provenance: RevisionProvenance
|
|
107
|
+
head_provenance: RevisionProvenance
|
|
108
|
+
generated_at: datetime
|
|
109
|
+
verdict: str # "improved", "neutral", "degraded", "regressive_cycles"
|
|
110
|
+
module_changes: ModuleChanges
|
|
111
|
+
dependency_changes: DependencyChanges
|
|
112
|
+
cycle_changes: CycleChanges
|
|
113
|
+
significant_coupling_deltas: list[CouplingDeltaItem] = Field(default_factory=list)
|
|
114
|
+
health_delta: HealthScoreDelta
|
|
115
|
+
finding_changes: RuleFindingChanges
|
|
116
|
+
coverage_delta: CoverageDelta
|
|
117
|
+
summary_text: str
|