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/live/diff.py
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"""Live Architecture Diff Engine: typed structural deltas between consecutive working-tree snapshots."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import uuid
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from repodna.contract.evaluator import ContractEvaluator
|
|
9
|
+
from repodna.contract.loader import find_contract_file, load_contract_file
|
|
10
|
+
from repodna.diff.engine import ArchitectureDiffEngine
|
|
11
|
+
from repodna.live.models import (
|
|
12
|
+
ContractDeltaItem,
|
|
13
|
+
CouplingHotspotDelta,
|
|
14
|
+
CycleDeltaSummary,
|
|
15
|
+
EdgeChangeItem,
|
|
16
|
+
LiveArchitectureDelta,
|
|
17
|
+
RenamedModuleDelta,
|
|
18
|
+
SymbolDeltaItem,
|
|
19
|
+
)
|
|
20
|
+
from repodna.schemas.models import AnalysisResult
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _is_public_symbol(symbol_name: str) -> bool:
|
|
24
|
+
"""Statically conservative heuristic for public interface symbols (excludes leading underscore privates)."""
|
|
25
|
+
if not symbol_name:
|
|
26
|
+
return False
|
|
27
|
+
if symbol_name.startswith("_") and not (symbol_name.startswith("__") and symbol_name.endswith("__")):
|
|
28
|
+
return False
|
|
29
|
+
return True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _snapshot_id_of(result: AnalysisResult) -> str:
|
|
33
|
+
if result.performance and result.performance.snapshot_identity:
|
|
34
|
+
return result.performance.snapshot_identity
|
|
35
|
+
if result.git_insights.snapshot_identity:
|
|
36
|
+
return result.git_insights.snapshot_identity
|
|
37
|
+
return result.analysis_id
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class LiveDiffEngine:
|
|
41
|
+
"""
|
|
42
|
+
Computes typed structural architectural deltas between consecutive verified
|
|
43
|
+
working-tree `AnalysisResult` snapshots, reusing `ArchitectureDiffEngine`
|
|
44
|
+
and `ContractEvaluator`.
|
|
45
|
+
|
|
46
|
+
Correctness invariants:
|
|
47
|
+
- Body-only function edits with zero structural changes report `has_architectural_changes=False`.
|
|
48
|
+
- Pre-existing cycles are never reported as new cycles.
|
|
49
|
+
- Cycles hidden by coverage collapse or scan truncation are NEVER reported as resolved.
|
|
50
|
+
- Rename matches without exact content-hash equality are explicitly marked `status="candidate"`.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def compute_delta(
|
|
55
|
+
*,
|
|
56
|
+
before: AnalysisResult | None,
|
|
57
|
+
after: AnalysisResult,
|
|
58
|
+
root_path: Path | None = None,
|
|
59
|
+
before_file_hashes: dict[str, str] | None = None,
|
|
60
|
+
after_file_hashes: dict[str, str] | None = None,
|
|
61
|
+
) -> LiveArchitectureDelta:
|
|
62
|
+
after_snap_id = _snapshot_id_of(after)
|
|
63
|
+
delta_id = f"delta_{uuid.uuid4().hex[:12]}"
|
|
64
|
+
|
|
65
|
+
if before is None:
|
|
66
|
+
completeness = "truncated" if after.transparency.truncated_by_limits else (
|
|
67
|
+
"complete" if after.health_report.dependency_graph_evaluated else "partial"
|
|
68
|
+
)
|
|
69
|
+
return LiveArchitectureDelta(
|
|
70
|
+
delta_id=delta_id,
|
|
71
|
+
before_snapshot_identity=None,
|
|
72
|
+
after_snapshot_identity=after_snap_id,
|
|
73
|
+
has_architectural_changes=False,
|
|
74
|
+
confidence=after.health_report.confidence,
|
|
75
|
+
completeness=completeness,
|
|
76
|
+
persisting_cycles_count=len(after.cycles),
|
|
77
|
+
health_score_before=None,
|
|
78
|
+
health_score_after=after.health_report.overall_score,
|
|
79
|
+
health_score_delta=None,
|
|
80
|
+
ast_coverage_before_pct=after.transparency.ast_loc_coverage_pct,
|
|
81
|
+
ast_coverage_after_pct=after.transparency.ast_loc_coverage_pct,
|
|
82
|
+
coverage_delta_pct=0.0,
|
|
83
|
+
summary_text=(
|
|
84
|
+
f"Initial verified snapshot ({after.total_files} files, "
|
|
85
|
+
f"{len(after.edges)} edges, {len(after.cycles)} cycles)."
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
before_snap_id = _snapshot_id_of(before)
|
|
90
|
+
caveats: list[str] = []
|
|
91
|
+
|
|
92
|
+
# Exact content-hash rename detection (verified) before calling ArchitectureDiffEngine
|
|
93
|
+
exact_renames: dict[str, str] = {}
|
|
94
|
+
if before_file_hashes and after_file_hashes:
|
|
95
|
+
before_ids_h = set(before_file_hashes.keys())
|
|
96
|
+
after_ids_h = set(after_file_hashes.keys())
|
|
97
|
+
removed_h = sorted(before_ids_h - after_ids_h)
|
|
98
|
+
added_h = sorted(after_ids_h - before_ids_h)
|
|
99
|
+
removed_by_sha: dict[str, list[str]] = {}
|
|
100
|
+
for r_p in removed_h:
|
|
101
|
+
removed_by_sha.setdefault(before_file_hashes[r_p], []).append(r_p)
|
|
102
|
+
for a_p in added_h:
|
|
103
|
+
sha = after_file_hashes[a_p]
|
|
104
|
+
cands = removed_by_sha.get(sha)
|
|
105
|
+
if cands:
|
|
106
|
+
exact_renames[cands.pop(0)] = a_p
|
|
107
|
+
|
|
108
|
+
base_diff = ArchitectureDiffEngine.compare_analyses(
|
|
109
|
+
base=before,
|
|
110
|
+
head=after,
|
|
111
|
+
base_ref=before_snap_id[:16],
|
|
112
|
+
head_ref=after_snap_id[:16],
|
|
113
|
+
base_is_working_tree=True,
|
|
114
|
+
head_is_working_tree=True,
|
|
115
|
+
git_renames=exact_renames or None,
|
|
116
|
+
)
|
|
117
|
+
caveats.extend(base_diff.coverage_delta.caveats)
|
|
118
|
+
|
|
119
|
+
# Coverage & completeness assessment
|
|
120
|
+
cov_before = before.transparency.ast_loc_coverage_pct
|
|
121
|
+
cov_after = after.transparency.ast_loc_coverage_pct
|
|
122
|
+
cov_delta = round(cov_after - cov_before, 2)
|
|
123
|
+
|
|
124
|
+
graph_eval_lost = (
|
|
125
|
+
before.health_report.dependency_graph_evaluated
|
|
126
|
+
and not after.health_report.dependency_graph_evaluated
|
|
127
|
+
)
|
|
128
|
+
graph_eval_recovered = (
|
|
129
|
+
not before.health_report.dependency_graph_evaluated
|
|
130
|
+
and after.health_report.dependency_graph_evaluated
|
|
131
|
+
)
|
|
132
|
+
trunc_started = (
|
|
133
|
+
not before.transparency.truncated_by_limits
|
|
134
|
+
and after.transparency.truncated_by_limits
|
|
135
|
+
)
|
|
136
|
+
trunc_cleared = (
|
|
137
|
+
before.transparency.truncated_by_limits
|
|
138
|
+
and not after.transparency.truncated_by_limits
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
coverage_regressed = (
|
|
142
|
+
graph_eval_lost
|
|
143
|
+
or trunc_started
|
|
144
|
+
or (cov_delta <= -5.0 and after.total_files > 0)
|
|
145
|
+
)
|
|
146
|
+
coverage_recovered = (
|
|
147
|
+
not coverage_regressed
|
|
148
|
+
and (graph_eval_recovered or trunc_cleared or cov_delta >= 5.0)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
completeness = "complete"
|
|
152
|
+
if after.transparency.truncated_by_limits:
|
|
153
|
+
completeness = "truncated"
|
|
154
|
+
caveats.append("After-snapshot was truncated by scan limits; delta may be incomplete.")
|
|
155
|
+
elif not after.health_report.dependency_graph_evaluated:
|
|
156
|
+
completeness = "partial"
|
|
157
|
+
caveats.append("Dependency graph was not evaluated due to insufficient AST coverage.")
|
|
158
|
+
|
|
159
|
+
# Modules & renames with explicit verified vs candidate status
|
|
160
|
+
renamed_modules: list[RenamedModuleDelta] = []
|
|
161
|
+
for rm in base_diff.module_changes.renamed:
|
|
162
|
+
is_verified = rm.old_path in exact_renames and exact_renames[rm.old_path] == rm.new_path
|
|
163
|
+
renamed_modules.append(
|
|
164
|
+
RenamedModuleDelta(
|
|
165
|
+
old_path=rm.old_path,
|
|
166
|
+
new_path=rm.new_path,
|
|
167
|
+
confidence=1.0 if is_verified else rm.confidence,
|
|
168
|
+
status="verified" if is_verified else "candidate",
|
|
169
|
+
reason=(
|
|
170
|
+
"Exact SHA-256 content match across rename"
|
|
171
|
+
if is_verified
|
|
172
|
+
else f"Candidate heuristic rename: {rm.reason}"
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# Edges: added, removed, and changed relationship (import_names or cycle participation changed)
|
|
178
|
+
before_edge_map = {(e.source, e.target): e for e in before.edges}
|
|
179
|
+
after_edge_map = {(e.source, e.target): e for e in after.edges}
|
|
180
|
+
|
|
181
|
+
added_edges = [
|
|
182
|
+
EdgeChangeItem(
|
|
183
|
+
source=e.source,
|
|
184
|
+
target=e.target,
|
|
185
|
+
change_type="added",
|
|
186
|
+
import_names_after=list(e.import_names),
|
|
187
|
+
in_cycle=e.in_cycle,
|
|
188
|
+
)
|
|
189
|
+
for key, e in sorted(after_edge_map.items())
|
|
190
|
+
if key not in before_edge_map
|
|
191
|
+
]
|
|
192
|
+
removed_edges = [
|
|
193
|
+
EdgeChangeItem(
|
|
194
|
+
source=e.source,
|
|
195
|
+
target=e.target,
|
|
196
|
+
change_type="removed",
|
|
197
|
+
import_names_before=list(e.import_names),
|
|
198
|
+
in_cycle=e.in_cycle,
|
|
199
|
+
)
|
|
200
|
+
for key, e in sorted(before_edge_map.items())
|
|
201
|
+
if key not in after_edge_map
|
|
202
|
+
]
|
|
203
|
+
changed_edges: list[EdgeChangeItem] = []
|
|
204
|
+
for key in sorted(set(before_edge_map.keys()) & set(after_edge_map.keys())):
|
|
205
|
+
b_e = before_edge_map[key]
|
|
206
|
+
a_e = after_edge_map[key]
|
|
207
|
+
if sorted(b_e.import_names) != sorted(a_e.import_names):
|
|
208
|
+
changed_edges.append(
|
|
209
|
+
EdgeChangeItem(
|
|
210
|
+
source=a_e.source,
|
|
211
|
+
target=a_e.target,
|
|
212
|
+
change_type="changed",
|
|
213
|
+
import_names_before=list(b_e.import_names),
|
|
214
|
+
import_names_after=list(a_e.import_names),
|
|
215
|
+
in_cycle=a_e.in_cycle,
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
# Cycles: guard against false resolution when coverage dropped or scan truncated
|
|
220
|
+
new_cycles = [
|
|
221
|
+
CycleDeltaSummary(
|
|
222
|
+
id=c.id,
|
|
223
|
+
nodes=list(c.nodes),
|
|
224
|
+
length=c.length,
|
|
225
|
+
severity=c.severity,
|
|
226
|
+
description=c.description,
|
|
227
|
+
)
|
|
228
|
+
for c in base_diff.cycle_changes.new_cycles
|
|
229
|
+
]
|
|
230
|
+
if completeness != "complete" or coverage_regressed:
|
|
231
|
+
resolved_cycles: list[CycleDeltaSummary] = []
|
|
232
|
+
if base_diff.cycle_changes.resolved_cycles:
|
|
233
|
+
caveats.append(
|
|
234
|
+
f"{len(base_diff.cycle_changes.resolved_cycles)} cycle(s) not observed after coverage drop/truncation; "
|
|
235
|
+
"not marked resolved without verified full graph coverage."
|
|
236
|
+
)
|
|
237
|
+
else:
|
|
238
|
+
resolved_cycles = [
|
|
239
|
+
CycleDeltaSummary(
|
|
240
|
+
id=c.id,
|
|
241
|
+
nodes=list(c.nodes),
|
|
242
|
+
length=c.length,
|
|
243
|
+
severity=c.severity,
|
|
244
|
+
description=c.description,
|
|
245
|
+
)
|
|
246
|
+
for c in base_diff.cycle_changes.resolved_cycles
|
|
247
|
+
]
|
|
248
|
+
|
|
249
|
+
# Architecture contract regressions & resolutions (if .repodna/architecture.yml exists)
|
|
250
|
+
new_contract_viols: list[ContractDeltaItem] = []
|
|
251
|
+
resolved_contract_viols: list[ContractDeltaItem] = []
|
|
252
|
+
if root_path is not None and root_path.exists():
|
|
253
|
+
c_file = find_contract_file(root_path)
|
|
254
|
+
if c_file is not None:
|
|
255
|
+
try:
|
|
256
|
+
contract = load_contract_file(c_file)
|
|
257
|
+
evaluator = ContractEvaluator(contract=contract)
|
|
258
|
+
b_rep = evaluator.evaluate(before)
|
|
259
|
+
a_rep = evaluator.evaluate(after)
|
|
260
|
+
b_vmap = {(v.rule_id, v.source_file, v.target_file): v for v in b_rep.violations}
|
|
261
|
+
a_vmap = {(v.rule_id, v.source_file, v.target_file): v for v in a_rep.violations}
|
|
262
|
+
for k, v in sorted(a_vmap.items()):
|
|
263
|
+
if k not in b_vmap:
|
|
264
|
+
new_contract_viols.append(
|
|
265
|
+
ContractDeltaItem(
|
|
266
|
+
rule_id=v.rule_id,
|
|
267
|
+
rule_title=v.rule_title,
|
|
268
|
+
severity=v.severity.value,
|
|
269
|
+
source_file=v.source_file,
|
|
270
|
+
target_file=v.target_file,
|
|
271
|
+
line=v.line,
|
|
272
|
+
message=v.message,
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
if completeness == "complete" and not coverage_regressed:
|
|
276
|
+
for k, v in sorted(b_vmap.items()):
|
|
277
|
+
if k not in a_vmap:
|
|
278
|
+
resolved_contract_viols.append(
|
|
279
|
+
ContractDeltaItem(
|
|
280
|
+
rule_id=v.rule_id,
|
|
281
|
+
rule_title=v.rule_title,
|
|
282
|
+
severity=v.severity.value,
|
|
283
|
+
source_file=v.source_file,
|
|
284
|
+
target_file=v.target_file,
|
|
285
|
+
line=v.line,
|
|
286
|
+
message=v.message,
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
except Exception as exc:
|
|
290
|
+
caveats.append(f"Architecture contract evaluation skipped due to invalid contract: {exc}")
|
|
291
|
+
|
|
292
|
+
# Coupling & new high-coupling hotspots
|
|
293
|
+
before_files_map = {f.id: f for f in before.files}
|
|
294
|
+
after_files_map = {f.id: f for f in after.files}
|
|
295
|
+
coupling_deltas: list[CouplingHotspotDelta] = []
|
|
296
|
+
new_hotspots: list[str] = []
|
|
297
|
+
|
|
298
|
+
for fid in sorted(set(before_files_map.keys()) & set(after_files_map.keys())):
|
|
299
|
+
b_f = before_files_map[fid]
|
|
300
|
+
a_f = after_files_map[fid]
|
|
301
|
+
fi_d = a_f.fan_in - b_f.fan_in
|
|
302
|
+
fo_d = a_f.fan_out - b_f.fan_out
|
|
303
|
+
inst_d = round(a_f.instability - b_f.instability, 3)
|
|
304
|
+
became_hotspot = (not b_f.is_hub and a_f.is_hub) or (b_f.fan_out < 8 <= a_f.fan_out)
|
|
305
|
+
if became_hotspot:
|
|
306
|
+
new_hotspots.append(fid)
|
|
307
|
+
if fi_d != 0 or fo_d != 0 or abs(inst_d) >= 0.05 or became_hotspot:
|
|
308
|
+
coupling_deltas.append(
|
|
309
|
+
CouplingHotspotDelta(
|
|
310
|
+
file_id=fid,
|
|
311
|
+
fan_in_before=b_f.fan_in,
|
|
312
|
+
fan_in_after=a_f.fan_in,
|
|
313
|
+
fan_in_delta=fi_d,
|
|
314
|
+
fan_out_before=b_f.fan_out,
|
|
315
|
+
fan_out_after=a_f.fan_out,
|
|
316
|
+
fan_out_delta=fo_d,
|
|
317
|
+
instability_before=b_f.instability,
|
|
318
|
+
instability_after=a_f.instability,
|
|
319
|
+
instability_delta=inst_d,
|
|
320
|
+
is_new_hotspot=became_hotspot,
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
# Symbol additions / removals & public interface changes
|
|
325
|
+
symbol_changes: list[SymbolDeltaItem] = []
|
|
326
|
+
public_interface_changes: list[SymbolDeltaItem] = []
|
|
327
|
+
|
|
328
|
+
for fid in sorted(set(before_files_map.keys()) & set(after_files_map.keys())):
|
|
329
|
+
b_syms = {(s.name, s.kind): s.line for s in before_files_map[fid].symbols}
|
|
330
|
+
a_syms = {(s.name, s.kind): s.line for s in after_files_map[fid].symbols}
|
|
331
|
+
|
|
332
|
+
for (sname, skind), line_a in sorted(a_syms.items()):
|
|
333
|
+
if (sname, skind) not in b_syms:
|
|
334
|
+
item = SymbolDeltaItem(
|
|
335
|
+
file_id=fid,
|
|
336
|
+
symbol_name=sname,
|
|
337
|
+
kind=skind,
|
|
338
|
+
change_type="added",
|
|
339
|
+
line_after=line_a,
|
|
340
|
+
)
|
|
341
|
+
symbol_changes.append(item)
|
|
342
|
+
if _is_public_symbol(sname):
|
|
343
|
+
public_interface_changes.append(item)
|
|
344
|
+
|
|
345
|
+
for (sname, skind), line_b in sorted(b_syms.items()):
|
|
346
|
+
if (sname, skind) not in a_syms:
|
|
347
|
+
item = SymbolDeltaItem(
|
|
348
|
+
file_id=fid,
|
|
349
|
+
symbol_name=sname,
|
|
350
|
+
kind=skind,
|
|
351
|
+
change_type="removed",
|
|
352
|
+
line_before=line_b,
|
|
353
|
+
)
|
|
354
|
+
symbol_changes.append(item)
|
|
355
|
+
if _is_public_symbol(sname):
|
|
356
|
+
public_interface_changes.append(item)
|
|
357
|
+
|
|
358
|
+
# Bound symbol lists for safe serialization on massive bursts
|
|
359
|
+
symbol_changes_bounded = symbol_changes[:200]
|
|
360
|
+
public_interface_bounded = public_interface_changes[:100]
|
|
361
|
+
|
|
362
|
+
has_arch_changes = bool(
|
|
363
|
+
base_diff.module_changes.added
|
|
364
|
+
or base_diff.module_changes.removed
|
|
365
|
+
or renamed_modules
|
|
366
|
+
or added_edges
|
|
367
|
+
or removed_edges
|
|
368
|
+
or changed_edges
|
|
369
|
+
or new_cycles
|
|
370
|
+
or resolved_cycles
|
|
371
|
+
or new_contract_viols
|
|
372
|
+
or resolved_contract_viols
|
|
373
|
+
or coupling_deltas
|
|
374
|
+
or new_hotspots
|
|
375
|
+
or symbol_changes_bounded
|
|
376
|
+
or coverage_regressed
|
|
377
|
+
or coverage_recovered
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
evidence_freshness_changed = before_snap_id != after_snap_id
|
|
381
|
+
|
|
382
|
+
# Human-readable summary
|
|
383
|
+
if not has_arch_changes:
|
|
384
|
+
summary = "No architectural graph or interface changes detected in this working-tree update."
|
|
385
|
+
else:
|
|
386
|
+
parts: list[str] = []
|
|
387
|
+
if base_diff.module_changes.added or base_diff.module_changes.removed or renamed_modules:
|
|
388
|
+
parts.append(
|
|
389
|
+
f"modules +{len(base_diff.module_changes.added)}/-{len(base_diff.module_changes.removed)}"
|
|
390
|
+
+ (f"/~{len(renamed_modules)} renamed" if renamed_modules else "")
|
|
391
|
+
)
|
|
392
|
+
if added_edges or removed_edges or changed_edges:
|
|
393
|
+
parts.append(
|
|
394
|
+
f"edges +{len(added_edges)}/-{len(removed_edges)}"
|
|
395
|
+
+ (f"/~{len(changed_edges)} updated" if changed_edges else "")
|
|
396
|
+
)
|
|
397
|
+
if new_cycles or resolved_cycles:
|
|
398
|
+
parts.append(f"cycles +{len(new_cycles)} new/-{len(resolved_cycles)} resolved")
|
|
399
|
+
if new_contract_viols or resolved_contract_viols:
|
|
400
|
+
parts.append(
|
|
401
|
+
f"contract +{len(new_contract_viols)}/-{len(resolved_contract_viols)}"
|
|
402
|
+
)
|
|
403
|
+
if public_interface_bounded:
|
|
404
|
+
parts.append(f"{len(public_interface_bounded)} public symbol change(s)")
|
|
405
|
+
if coverage_regressed:
|
|
406
|
+
parts.append(f"AST coverage regressed ({cov_before:.1f}% -> {cov_after:.1f}%)")
|
|
407
|
+
elif coverage_recovered:
|
|
408
|
+
parts.append(f"AST coverage recovered ({cov_before:.1f}% -> {cov_after:.1f}%)")
|
|
409
|
+
summary = "Architectural delta: " + "; ".join(parts) + "."
|
|
410
|
+
|
|
411
|
+
return LiveArchitectureDelta(
|
|
412
|
+
delta_id=delta_id,
|
|
413
|
+
before_snapshot_identity=before_snap_id,
|
|
414
|
+
after_snapshot_identity=after_snap_id,
|
|
415
|
+
has_architectural_changes=has_arch_changes,
|
|
416
|
+
confidence=after.health_report.confidence,
|
|
417
|
+
completeness=completeness,
|
|
418
|
+
caveats=caveats,
|
|
419
|
+
added_modules=list(base_diff.module_changes.added),
|
|
420
|
+
removed_modules=list(base_diff.module_changes.removed),
|
|
421
|
+
renamed_modules=renamed_modules,
|
|
422
|
+
added_edges=added_edges,
|
|
423
|
+
removed_edges=removed_edges,
|
|
424
|
+
changed_edges=changed_edges,
|
|
425
|
+
new_cycles=new_cycles,
|
|
426
|
+
resolved_cycles=resolved_cycles,
|
|
427
|
+
persisting_cycles_count=base_diff.cycle_changes.persisting_cycles,
|
|
428
|
+
new_contract_violations=new_contract_viols,
|
|
429
|
+
resolved_contract_violations=resolved_contract_viols,
|
|
430
|
+
coupling_deltas=coupling_deltas[:100],
|
|
431
|
+
new_high_coupling_hotspots=sorted(set(new_hotspots)),
|
|
432
|
+
symbol_changes=symbol_changes_bounded,
|
|
433
|
+
public_interface_changes=public_interface_bounded,
|
|
434
|
+
health_score_before=before.health_report.overall_score,
|
|
435
|
+
health_score_after=after.health_report.overall_score,
|
|
436
|
+
health_score_delta=base_diff.health_delta.score_delta,
|
|
437
|
+
ast_coverage_before_pct=cov_before,
|
|
438
|
+
ast_coverage_after_pct=cov_after,
|
|
439
|
+
coverage_delta_pct=cov_delta,
|
|
440
|
+
coverage_regressed=coverage_regressed,
|
|
441
|
+
coverage_recovered=coverage_recovered,
|
|
442
|
+
evidence_freshness_changed=evidence_freshness_changed,
|
|
443
|
+
summary_text=summary,
|
|
444
|
+
)
|