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
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"""Typed Pydantic v2 schemas for RepoDNA."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SourceType(StrEnum):
|
|
13
|
+
LOCAL = "local"
|
|
14
|
+
GITHUB = "github"
|
|
15
|
+
DEMO = "demo"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ScanStatus(StrEnum):
|
|
19
|
+
QUEUED = "queued"
|
|
20
|
+
CLONING = "cloning"
|
|
21
|
+
DISCOVERING = "discovering"
|
|
22
|
+
PARSING = "parsing"
|
|
23
|
+
BUILDING_GRAPH = "building_graph"
|
|
24
|
+
ANALYZING_GIT = "analyzing_git"
|
|
25
|
+
EVALUATING_RULES = "evaluating_rules"
|
|
26
|
+
COMPLETED = "completed"
|
|
27
|
+
CANCELLED = "cancelled"
|
|
28
|
+
FAILED = "failed"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class LanguageSupportLevel(StrEnum):
|
|
32
|
+
FULL_AST = "full_ast" # Tree-sitter + static AST import & symbol extraction
|
|
33
|
+
PARTIAL_STATIC = "partial_static" # Static pattern import extraction
|
|
34
|
+
UNSUPPORTED = "unsupported" # Tracked for LOC/distribution, explicitly marked unsupported for imports
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SeverityLevel(StrEnum):
|
|
38
|
+
CRITICAL = "critical"
|
|
39
|
+
WARNING = "warning"
|
|
40
|
+
INFO = "info"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ScanLimits(BaseModel):
|
|
44
|
+
model_config = ConfigDict(extra="forbid")
|
|
45
|
+
|
|
46
|
+
max_files: int = Field(default=2500, ge=10, le=20000, description="Maximum number of files to scan.")
|
|
47
|
+
max_file_size_bytes: int = Field(
|
|
48
|
+
default=1_048_576, ge=4096, le=10_485_760, description="Max single file size in bytes (default 1 MB)."
|
|
49
|
+
)
|
|
50
|
+
max_total_size_bytes: int = Field(
|
|
51
|
+
default=104_857_600, ge=65536, le=524_288_000, description="Max total scanned bytes (default 100 MB)."
|
|
52
|
+
)
|
|
53
|
+
timeout_seconds: float = Field(default=60.0, ge=5.0, le=300.0, description="Overall scan timeout in seconds.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ScanRequest(BaseModel):
|
|
57
|
+
model_config = ConfigDict(extra="forbid")
|
|
58
|
+
|
|
59
|
+
source_type: SourceType = Field(description="Whether scanning a local path, GitHub URL, or explicit demo.")
|
|
60
|
+
target: str = Field(min_length=1, max_length=1024, description="Local filesystem path, HTTPS GitHub URL, or 'demo'.")
|
|
61
|
+
branch: str | None = Field(default=None, max_length=128, description="Optional branch/tag for GitHub clone.")
|
|
62
|
+
limits: ScanLimits = Field(default_factory=ScanLimits)
|
|
63
|
+
analysis_mode: str = Field(
|
|
64
|
+
default="auto",
|
|
65
|
+
pattern=r"^(auto|full|incremental)$",
|
|
66
|
+
description="Analysis execution strategy: 'auto', 'full', or 'incremental'.",
|
|
67
|
+
)
|
|
68
|
+
use_cache: bool = Field(
|
|
69
|
+
default=True,
|
|
70
|
+
description="Whether to read from and write to the persistent content-addressable cache.",
|
|
71
|
+
)
|
|
72
|
+
workers: int | None = Field(
|
|
73
|
+
default=None,
|
|
74
|
+
ge=1,
|
|
75
|
+
le=32,
|
|
76
|
+
description="Optional bounded worker limit for parallel parsing (None = automatic).",
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class ScanProgress(BaseModel):
|
|
81
|
+
job_id: str
|
|
82
|
+
status: ScanStatus
|
|
83
|
+
phase_message: str
|
|
84
|
+
progress_percent: float = Field(ge=0.0, le=100.0)
|
|
85
|
+
files_discovered: int = 0
|
|
86
|
+
files_processed: int = 0
|
|
87
|
+
started_at: datetime
|
|
88
|
+
updated_at: datetime
|
|
89
|
+
error_code: str | None = None
|
|
90
|
+
error_message: str | None = None
|
|
91
|
+
current_phase: str | None = None
|
|
92
|
+
reused_files: int = 0
|
|
93
|
+
reparsed_files: int = 0
|
|
94
|
+
cache_status: str | None = None
|
|
95
|
+
elapsed_ms: int = 0
|
|
96
|
+
workers_used: int = 1
|
|
97
|
+
analysis_mode: str | None = None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class UnresolvedReference(BaseModel):
|
|
101
|
+
source_file: str
|
|
102
|
+
raw_import: str
|
|
103
|
+
line: int
|
|
104
|
+
reason: str = Field(description="Why this import was not linked to an internal file (e.g., external_package, dynamic_import, unresolvable_path).")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class SymbolItem(BaseModel):
|
|
108
|
+
name: str
|
|
109
|
+
kind: str # "class", "function", "interface", "type", "struct"
|
|
110
|
+
line: int
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class FileNode(BaseModel):
|
|
114
|
+
id: str = Field(description="Normalized POSIX relative path within repository.")
|
|
115
|
+
name: str
|
|
116
|
+
directory: str
|
|
117
|
+
extension: str
|
|
118
|
+
language: str
|
|
119
|
+
support_level: LanguageSupportLevel
|
|
120
|
+
size_bytes: int
|
|
121
|
+
lines_total: int
|
|
122
|
+
lines_code: int
|
|
123
|
+
lines_comment: int
|
|
124
|
+
lines_blank: int
|
|
125
|
+
imports_internal: list[str] = Field(default_factory=list, description="Resolved internal file IDs.")
|
|
126
|
+
imported_by: list[str] = Field(default_factory=list, description="Internal file IDs that import this file.")
|
|
127
|
+
imports_external: list[str] = Field(default_factory=list, description="External library/package names.")
|
|
128
|
+
unresolved_imports: list[UnresolvedReference] = Field(default_factory=list)
|
|
129
|
+
symbols: list[SymbolItem] = Field(default_factory=list)
|
|
130
|
+
fan_in: int = 0
|
|
131
|
+
fan_out: int = 0
|
|
132
|
+
instability: float = Field(default=0.0, description="Robert C. Martin Instability metric I = Ce / (Ca + Ce).")
|
|
133
|
+
in_cycle: bool = False
|
|
134
|
+
cycle_ids: list[str] = Field(default_factory=list)
|
|
135
|
+
is_orphan: bool = False
|
|
136
|
+
is_hub: bool = False
|
|
137
|
+
git_commits: int = 0
|
|
138
|
+
git_last_author: str | None = None
|
|
139
|
+
git_last_modified: str | None = None
|
|
140
|
+
secret_warnings: list[str] = Field(default_factory=list)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class DependencyEdge(BaseModel):
|
|
144
|
+
id: str
|
|
145
|
+
source: str
|
|
146
|
+
target: str
|
|
147
|
+
import_names: list[str] = Field(default_factory=list)
|
|
148
|
+
line: int = 1
|
|
149
|
+
in_cycle: bool = False
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class CycleGroup(BaseModel):
|
|
153
|
+
id: str
|
|
154
|
+
nodes: list[str] = Field(description="Ordered cycle path of file IDs, e.g. [A, B, C, A].")
|
|
155
|
+
length: int
|
|
156
|
+
severity: SeverityLevel
|
|
157
|
+
description: str
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class LanguageBreakdownItem(BaseModel):
|
|
161
|
+
language: str
|
|
162
|
+
support_level: LanguageSupportLevel
|
|
163
|
+
file_count: int
|
|
164
|
+
lines_code: int
|
|
165
|
+
lines_total: int
|
|
166
|
+
size_bytes: int
|
|
167
|
+
percentage_of_code: float
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class SkippedItem(BaseModel):
|
|
171
|
+
path: str
|
|
172
|
+
reason: str # "symlink_blocked", "file_size_limit", "binary_file", "max_files_limit", "ignored_directory", "path_traversal_blocked"
|
|
173
|
+
detail: str
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class TransparencyReport(BaseModel):
|
|
177
|
+
supported_languages_detected: list[str] = Field(default_factory=list)
|
|
178
|
+
partial_static_languages_detected: list[str] = Field(default_factory=list)
|
|
179
|
+
partial_static_files_count: int = 0
|
|
180
|
+
unsupported_languages_detected: list[str] = Field(default_factory=list)
|
|
181
|
+
unsupported_files_count: int = 0
|
|
182
|
+
ast_file_coverage_pct: float = 0.0
|
|
183
|
+
ast_loc_coverage_pct: float = 0.0
|
|
184
|
+
partial_static_file_coverage_pct: float = 0.0
|
|
185
|
+
partial_static_loc_coverage_pct: float = 0.0
|
|
186
|
+
unsupported_file_coverage_pct: float = 0.0
|
|
187
|
+
unsupported_loc_coverage_pct: float = 0.0
|
|
188
|
+
analysis_confidence: str = "high"
|
|
189
|
+
dependency_graph_evaluated: bool = True
|
|
190
|
+
unresolved_internal_imports_count: int = 0
|
|
191
|
+
dynamic_imports_count: int = 0
|
|
192
|
+
skipped_files: list[SkippedItem] = Field(default_factory=list)
|
|
193
|
+
truncated_by_limits: bool = False
|
|
194
|
+
truncation_reason: str | None = None
|
|
195
|
+
parser_engine_info: dict[str, str] = Field(default_factory=dict)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class GitCommitSummary(BaseModel):
|
|
199
|
+
sha: str
|
|
200
|
+
author: str
|
|
201
|
+
date: str
|
|
202
|
+
subject: str
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class GitHotspot(BaseModel):
|
|
206
|
+
path: str
|
|
207
|
+
commits: int
|
|
208
|
+
authors_count: int
|
|
209
|
+
lines_code: int
|
|
210
|
+
churn_risk_score: float = Field(description="Normalized product of commit frequency and file complexity.")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class GitInsights(BaseModel):
|
|
214
|
+
is_git_repo: bool
|
|
215
|
+
default_branch: str | None = None
|
|
216
|
+
commit_sha: str | None = None
|
|
217
|
+
is_dirty: bool = False
|
|
218
|
+
dirty_files_count: int = 0
|
|
219
|
+
verification_status: str = "UNVERIFIED_NON_GIT"
|
|
220
|
+
snapshot_identity: str | None = None
|
|
221
|
+
source_type: str = "git"
|
|
222
|
+
total_commits_scanned: int = 0
|
|
223
|
+
unique_contributors: int = 0
|
|
224
|
+
first_commit_date: str | None = None
|
|
225
|
+
latest_commit_date: str | None = None
|
|
226
|
+
recent_commits: list[GitCommitSummary] = Field(default_factory=list)
|
|
227
|
+
hotspots: list[GitHotspot] = Field(default_factory=list)
|
|
228
|
+
bus_factor_estimate: int = 1
|
|
229
|
+
note: str | None = None
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class RuleFinding(BaseModel):
|
|
233
|
+
rule_id: str
|
|
234
|
+
title: str
|
|
235
|
+
category: str # "cycles", "coupling", "complexity", "hygiene", "security"
|
|
236
|
+
severity: SeverityLevel
|
|
237
|
+
score_deduction: float
|
|
238
|
+
max_deduction: float
|
|
239
|
+
formula_explanation: str
|
|
240
|
+
threshold_description: str
|
|
241
|
+
affected_files: list[str] = Field(default_factory=list)
|
|
242
|
+
evidence: list[str] = Field(default_factory=list)
|
|
243
|
+
remediation: str
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class CategoryScore(BaseModel):
|
|
247
|
+
category: str
|
|
248
|
+
label: str
|
|
249
|
+
score: float | None = Field(default=None, ge=0.0, le=100.0)
|
|
250
|
+
status: str = Field(
|
|
251
|
+
default="evaluated",
|
|
252
|
+
description="Either 'evaluated', 'not_evaluated', 'partial', or 'insufficient_data'.",
|
|
253
|
+
)
|
|
254
|
+
weight: float
|
|
255
|
+
deductions: float
|
|
256
|
+
findings_count: int
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class ArchitectureHealthReport(BaseModel):
|
|
260
|
+
overall_score: float | None = Field(default=None, ge=0.0, le=100.0)
|
|
261
|
+
grade: str # "A", "B", "C", "D", "F", "N/A"
|
|
262
|
+
status: str = Field(
|
|
263
|
+
default="evaluated",
|
|
264
|
+
description="Either 'evaluated', 'insufficient_dependency_coverage', or 'insufficient_data'.",
|
|
265
|
+
)
|
|
266
|
+
confidence: str = Field(
|
|
267
|
+
default="high",
|
|
268
|
+
description="Either 'high', 'medium', 'low', or 'none'.",
|
|
269
|
+
)
|
|
270
|
+
confidence_reason: str = Field(default="")
|
|
271
|
+
ast_file_coverage_pct: float = 0.0
|
|
272
|
+
ast_loc_coverage_pct: float = 0.0
|
|
273
|
+
dependency_graph_evaluated: bool = True
|
|
274
|
+
cycle_analysis_summary: str = Field(default="")
|
|
275
|
+
methodology: str
|
|
276
|
+
category_scores: list[CategoryScore] = Field(default_factory=list)
|
|
277
|
+
findings: list[RuleFinding] = Field(default_factory=list)
|
|
278
|
+
passed_rules: list[str] = Field(default_factory=list)
|
|
279
|
+
unverified_rules: list[str] = Field(default_factory=list)
|
|
280
|
+
summary_metrics: dict[str, Any] = Field(default_factory=dict)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class GraphMetrics(BaseModel):
|
|
284
|
+
total_nodes: int = 0
|
|
285
|
+
total_edges: int = 0
|
|
286
|
+
connected_components: int = 0
|
|
287
|
+
scc_count: int = 0
|
|
288
|
+
cycle_count: int = 0
|
|
289
|
+
nodes_in_cycles: int = 0
|
|
290
|
+
cycles_truncated: bool = False
|
|
291
|
+
cycle_truncation_reason: str | None = None
|
|
292
|
+
orphan_files_count: int = 0
|
|
293
|
+
hub_files_count: int = 0
|
|
294
|
+
max_fan_in: int = 0
|
|
295
|
+
max_fan_out: int = 0
|
|
296
|
+
average_instability: float = 0.0
|
|
297
|
+
graph_density: float = 0.0
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class PerformanceMetrics(BaseModel):
|
|
301
|
+
"""Truthful, measured performance telemetry attached to an AnalysisResult."""
|
|
302
|
+
|
|
303
|
+
analysis_mode_requested: str = "auto"
|
|
304
|
+
analysis_mode_executed: str = "full"
|
|
305
|
+
cache_status: str = "miss"
|
|
306
|
+
fallback_reason: str | None = None
|
|
307
|
+
fallback_detail: str | None = None
|
|
308
|
+
snapshot_identity: str | None = None
|
|
309
|
+
previous_snapshot_identity: str | None = None
|
|
310
|
+
total_files: int = 0
|
|
311
|
+
reused_files: int = 0
|
|
312
|
+
reparsed_files: int = 0
|
|
313
|
+
added_files: int = 0
|
|
314
|
+
modified_files: int = 0
|
|
315
|
+
deleted_files: int = 0
|
|
316
|
+
renamed_files: int = 0
|
|
317
|
+
affected_closure_files: int = 0
|
|
318
|
+
cache_hits: int = 0
|
|
319
|
+
cache_misses: int = 0
|
|
320
|
+
cache_hit_ratio: float = 0.0
|
|
321
|
+
workers_requested: int = 1
|
|
322
|
+
workers_used: int = 1
|
|
323
|
+
parallel_mode: str = "sequential"
|
|
324
|
+
phase_timings_ms: dict[str, float] = Field(default_factory=dict)
|
|
325
|
+
peak_memory_mb: float = 0.0
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class AnalysisResult(BaseModel):
|
|
329
|
+
analysis_id: str
|
|
330
|
+
repo_name: str
|
|
331
|
+
source_type: SourceType
|
|
332
|
+
target_display: str
|
|
333
|
+
is_demo: bool = False
|
|
334
|
+
analyzed_at: datetime
|
|
335
|
+
duration_ms: int
|
|
336
|
+
total_files: int
|
|
337
|
+
total_lines_code: int
|
|
338
|
+
total_lines_all: int
|
|
339
|
+
total_size_bytes: int
|
|
340
|
+
languages: list[LanguageBreakdownItem]
|
|
341
|
+
files: list[FileNode]
|
|
342
|
+
edges: list[DependencyEdge]
|
|
343
|
+
cycles: list[CycleGroup]
|
|
344
|
+
graph_metrics: GraphMetrics
|
|
345
|
+
health_report: ArchitectureHealthReport
|
|
346
|
+
git_insights: GitInsights
|
|
347
|
+
transparency: TransparencyReport
|
|
348
|
+
performance: PerformanceMetrics | None = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Security package."""
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Bounded, alias-safe YAML loader protecting against YAML Billion Laughs and nesting DoS (SEC-07)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from repodna.security.validators import SecurityValidationError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class _BoundedSafeLoader(yaml.SafeLoader):
|
|
13
|
+
"""YAML SafeLoader that bounds node count, nesting depth, and alias expansion during composition."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
stream: str,
|
|
18
|
+
*,
|
|
19
|
+
max_nodes: int = 25_000,
|
|
20
|
+
max_depth: int = 32,
|
|
21
|
+
max_aliases: int = 0,
|
|
22
|
+
) -> None:
|
|
23
|
+
super().__init__(stream)
|
|
24
|
+
self._max_nodes = max_nodes
|
|
25
|
+
self._max_depth = max_depth
|
|
26
|
+
self._max_aliases = max_aliases
|
|
27
|
+
self._node_count = 0
|
|
28
|
+
self._alias_count = 0
|
|
29
|
+
self._current_depth = 0
|
|
30
|
+
|
|
31
|
+
def compose_node(self, parent: Any, index: Any) -> Any:
|
|
32
|
+
if self.check_event(yaml.AliasEvent):
|
|
33
|
+
self._alias_count += 1
|
|
34
|
+
if self._alias_count > self._max_aliases:
|
|
35
|
+
raise SecurityValidationError(
|
|
36
|
+
"YAML_ALIAS_DISALLOWED",
|
|
37
|
+
f"YAML alias expansion exceeded maximum allowed ({self._max_aliases}).",
|
|
38
|
+
)
|
|
39
|
+
self._node_count += 1
|
|
40
|
+
if self._node_count > self._max_nodes:
|
|
41
|
+
raise SecurityValidationError(
|
|
42
|
+
"YAML_NODE_LIMIT_EXCEEDED",
|
|
43
|
+
f"YAML document exceeded maximum allowed node count ({self._max_nodes}).",
|
|
44
|
+
)
|
|
45
|
+
self._current_depth += 1
|
|
46
|
+
if self._current_depth > self._max_depth:
|
|
47
|
+
raise SecurityValidationError(
|
|
48
|
+
"YAML_DEPTH_EXCEEDED",
|
|
49
|
+
f"YAML document exceeded maximum allowed nesting depth ({self._max_depth}).",
|
|
50
|
+
)
|
|
51
|
+
try:
|
|
52
|
+
return super().compose_node(parent, index)
|
|
53
|
+
finally:
|
|
54
|
+
self._current_depth -= 1
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def safe_load_bounded_yaml(
|
|
58
|
+
raw_text: str,
|
|
59
|
+
*,
|
|
60
|
+
max_bytes: int = 2 * 1024 * 1024,
|
|
61
|
+
max_nodes: int = 25_000,
|
|
62
|
+
max_depth: int = 32,
|
|
63
|
+
max_aliases: int = 0,
|
|
64
|
+
) -> Any:
|
|
65
|
+
"""Safely parses YAML with hard pre-expansion limits on bytes, nodes, depth, and aliases."""
|
|
66
|
+
encoded_len = len(raw_text.encode("utf-8", errors="replace"))
|
|
67
|
+
if encoded_len > max_bytes:
|
|
68
|
+
raise SecurityValidationError(
|
|
69
|
+
"YAML_SIZE_LIMIT_EXCEEDED",
|
|
70
|
+
f"YAML input ({encoded_len:,} bytes) exceeds maximum allowed ({max_bytes:,} bytes).",
|
|
71
|
+
)
|
|
72
|
+
loader = _BoundedSafeLoader(
|
|
73
|
+
raw_text,
|
|
74
|
+
max_nodes=max_nodes,
|
|
75
|
+
max_depth=max_depth,
|
|
76
|
+
max_aliases=max_aliases,
|
|
77
|
+
)
|
|
78
|
+
try:
|
|
79
|
+
return loader.get_single_data()
|
|
80
|
+
finally:
|
|
81
|
+
loader.dispose()
|