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/agent/deltas.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Acknowledged Context Deduplication and Delta Packs for RepoDNA v0.11.0.
|
|
2
|
+
|
|
3
|
+
Key guarantees:
|
|
4
|
+
- Server NEVER assumes the agent still holds previously sent blocks in its context window;
|
|
5
|
+
deduplication relies strictly on explicit `known_block_ids` / `known_block_hashes` from the client.
|
|
6
|
+
- If the client lacks required blocks or the snapshot changed incompatibly without overlap,
|
|
7
|
+
returns an explicit `full_fallback` mode so reconstruction is always safe.
|
|
8
|
+
- Reconstructing from `(client_cache, delta_response)` produces a block set semantically
|
|
9
|
+
equivalent to the full ContextPack.
|
|
10
|
+
- Reports full response bytes/tokens, delta response bytes/tokens, and repeated bytes avoided
|
|
11
|
+
separately from per-call MCP tool overhead.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
|
|
18
|
+
from repodna.agent.models import (
|
|
19
|
+
ContextBlock,
|
|
20
|
+
ContextDeltaRequest,
|
|
21
|
+
ContextDeltaResponse,
|
|
22
|
+
ContextPack,
|
|
23
|
+
)
|
|
24
|
+
from repodna.agent.token_budget import TokenCounter, build_context_budget
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def build_delta_pack(
|
|
28
|
+
full_pack: ContextPack,
|
|
29
|
+
delta_req: ContextDeltaRequest,
|
|
30
|
+
target_model: str = "generic",
|
|
31
|
+
tokenizer_pref: str = "auto",
|
|
32
|
+
) -> ContextDeltaResponse:
|
|
33
|
+
"""Computes an acknowledged delta pack from a compiled full ContextPack."""
|
|
34
|
+
full_blocks_json = json.dumps(
|
|
35
|
+
[b.model_dump(mode="json") for b in full_pack.blocks], sort_keys=True
|
|
36
|
+
)
|
|
37
|
+
full_bytes = len(full_blocks_json.encode("utf-8"))
|
|
38
|
+
full_tokens = TokenCounter.count(
|
|
39
|
+
full_blocks_json, target_model=target_model, tokenizer_pref=tokenizer_pref
|
|
40
|
+
).tokens
|
|
41
|
+
|
|
42
|
+
known_ids = set(delta_req.known_block_ids) | set(delta_req.known_block_hashes.keys())
|
|
43
|
+
|
|
44
|
+
# If client acknowledges nothing, perform safe full fallback
|
|
45
|
+
if not known_ids:
|
|
46
|
+
return ContextDeltaResponse(
|
|
47
|
+
mode="full_fallback",
|
|
48
|
+
fallback_reason="Client provided no acknowledged known_block_ids; returning self-contained full pack.",
|
|
49
|
+
repo_id=full_pack.freshness.repo_id,
|
|
50
|
+
snapshot_id=full_pack.freshness.snapshot_id,
|
|
51
|
+
task_id=full_pack.task.task_id,
|
|
52
|
+
added_blocks=list(full_pack.blocks),
|
|
53
|
+
updated_blocks=[],
|
|
54
|
+
invalidated_block_ids=[],
|
|
55
|
+
unchanged_block_references=[],
|
|
56
|
+
required_dependencies=[b.block_id for b in full_pack.blocks if b.required],
|
|
57
|
+
evidence=list(full_pack.evidence),
|
|
58
|
+
full_response_bytes=full_bytes,
|
|
59
|
+
delta_response_bytes=full_bytes,
|
|
60
|
+
repeated_context_bytes_avoided=0,
|
|
61
|
+
full_counted_tokens=full_tokens,
|
|
62
|
+
delta_counted_tokens=full_tokens,
|
|
63
|
+
budget=full_pack.budget,
|
|
64
|
+
trust_boundary=full_pack.trust_boundary,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
current_by_id = {b.block_id: b for b in full_pack.blocks}
|
|
68
|
+
current_by_scope = {(b.block_type, b.scope): b for b in full_pack.blocks}
|
|
69
|
+
|
|
70
|
+
added: list[ContextBlock] = []
|
|
71
|
+
updated: list[ContextBlock] = []
|
|
72
|
+
unchanged_refs: list[str] = []
|
|
73
|
+
repeated_bytes_avoided = 0
|
|
74
|
+
|
|
75
|
+
for blk in full_pack.blocks:
|
|
76
|
+
if blk.block_id in known_ids:
|
|
77
|
+
known_hash = delta_req.known_block_hashes.get(blk.block_id)
|
|
78
|
+
if known_hash is None or known_hash == blk.content_hash:
|
|
79
|
+
unchanged_refs.append(blk.block_id)
|
|
80
|
+
repeated_bytes_avoided += len(blk.model_dump_json().encode("utf-8"))
|
|
81
|
+
else:
|
|
82
|
+
updated.append(blk)
|
|
83
|
+
else:
|
|
84
|
+
# Check if an older version of the same (block_type, scope) was known
|
|
85
|
+
# (meaning content changed across snapshots -> send as updated)
|
|
86
|
+
if delta_req.previous_snapshot_id and delta_req.previous_snapshot_id != full_pack.freshness.snapshot_id:
|
|
87
|
+
updated.append(blk)
|
|
88
|
+
else:
|
|
89
|
+
added.append(blk)
|
|
90
|
+
|
|
91
|
+
invalidated = sorted(kid for kid in known_ids if kid not in current_by_id)
|
|
92
|
+
_ = current_by_scope # reserved for future scope-level diagnostics
|
|
93
|
+
|
|
94
|
+
# If zero blocks were unchanged and allow_full_fallback is enabled, emit clean full_fallback
|
|
95
|
+
if not unchanged_refs and delta_req.allow_full_fallback:
|
|
96
|
+
return ContextDeltaResponse(
|
|
97
|
+
mode="full_fallback",
|
|
98
|
+
fallback_reason="No acknowledged blocks matched current snapshot/content hashes; returning full pack.",
|
|
99
|
+
repo_id=full_pack.freshness.repo_id,
|
|
100
|
+
snapshot_id=full_pack.freshness.snapshot_id,
|
|
101
|
+
task_id=full_pack.task.task_id,
|
|
102
|
+
added_blocks=list(full_pack.blocks),
|
|
103
|
+
updated_blocks=[],
|
|
104
|
+
invalidated_block_ids=invalidated,
|
|
105
|
+
unchanged_block_references=[],
|
|
106
|
+
required_dependencies=[b.block_id for b in full_pack.blocks if b.required],
|
|
107
|
+
evidence=list(full_pack.evidence),
|
|
108
|
+
full_response_bytes=full_bytes,
|
|
109
|
+
delta_response_bytes=full_bytes,
|
|
110
|
+
repeated_context_bytes_avoided=0,
|
|
111
|
+
full_counted_tokens=full_tokens,
|
|
112
|
+
delta_counted_tokens=full_tokens,
|
|
113
|
+
budget=full_pack.budget,
|
|
114
|
+
trust_boundary=full_pack.trust_boundary,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Filter evidence to only what is referenced by added/updated blocks
|
|
118
|
+
delta_ev_ids = {eid for b in [*added, *updated] for eid in b.evidence_ids}
|
|
119
|
+
delta_evidence = [e for e in full_pack.evidence if e.evidence_id in delta_ev_ids]
|
|
120
|
+
|
|
121
|
+
delta_payload_json = json.dumps(
|
|
122
|
+
{
|
|
123
|
+
"added": [b.model_dump(mode="json") for b in added],
|
|
124
|
+
"updated": [b.model_dump(mode="json") for b in updated],
|
|
125
|
+
"invalidated": invalidated,
|
|
126
|
+
"unchanged_refs": unchanged_refs,
|
|
127
|
+
},
|
|
128
|
+
sort_keys=True,
|
|
129
|
+
)
|
|
130
|
+
delta_bytes = len(delta_payload_json.encode("utf-8"))
|
|
131
|
+
delta_tokens = TokenCounter.count(
|
|
132
|
+
delta_payload_json, target_model=target_model, tokenizer_pref=tokenizer_pref
|
|
133
|
+
).tokens
|
|
134
|
+
|
|
135
|
+
delta_budget = build_context_budget(
|
|
136
|
+
serialized_payload=delta_payload_json,
|
|
137
|
+
requested_budget=full_pack.budget.requested_budget,
|
|
138
|
+
required_minimum_budget=min(full_pack.budget.required_minimum_budget, delta_tokens),
|
|
139
|
+
target_model=target_model,
|
|
140
|
+
tokenizer_pref=tokenizer_pref,
|
|
141
|
+
omitted_sections=full_pack.budget.omitted_sections,
|
|
142
|
+
omitted_candidates=full_pack.budget.omitted_candidates,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
return ContextDeltaResponse(
|
|
146
|
+
mode="delta",
|
|
147
|
+
repo_id=full_pack.freshness.repo_id,
|
|
148
|
+
snapshot_id=full_pack.freshness.snapshot_id,
|
|
149
|
+
task_id=full_pack.task.task_id,
|
|
150
|
+
added_blocks=added,
|
|
151
|
+
updated_blocks=updated,
|
|
152
|
+
invalidated_block_ids=invalidated,
|
|
153
|
+
unchanged_block_references=sorted(unchanged_refs),
|
|
154
|
+
required_dependencies=[b.block_id for b in full_pack.blocks if b.required],
|
|
155
|
+
evidence=delta_evidence,
|
|
156
|
+
full_response_bytes=full_bytes,
|
|
157
|
+
delta_response_bytes=delta_bytes,
|
|
158
|
+
repeated_context_bytes_avoided=repeated_bytes_avoided,
|
|
159
|
+
full_counted_tokens=full_tokens,
|
|
160
|
+
delta_counted_tokens=delta_tokens,
|
|
161
|
+
budget=delta_budget,
|
|
162
|
+
trust_boundary=full_pack.trust_boundary,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def reconstruct_blocks_from_delta(
|
|
167
|
+
client_blocks_by_id: dict[str, ContextBlock],
|
|
168
|
+
delta: ContextDeltaResponse,
|
|
169
|
+
) -> tuple[list[ContextBlock], list[str]]:
|
|
170
|
+
"""Reconstructs the active block list on the client side from cached blocks + delta.
|
|
171
|
+
|
|
172
|
+
Returns (reconstructed_blocks, missing_block_ids).
|
|
173
|
+
If `missing_block_ids` is non-empty, client must request a full context pack.
|
|
174
|
+
"""
|
|
175
|
+
working: dict[str, ContextBlock] = dict(client_blocks_by_id)
|
|
176
|
+
for inv_id in delta.invalidated_block_ids:
|
|
177
|
+
working.pop(inv_id, None)
|
|
178
|
+
|
|
179
|
+
missing: list[str] = []
|
|
180
|
+
out_map: dict[str, ContextBlock] = {}
|
|
181
|
+
|
|
182
|
+
for ref_id in delta.unchanged_block_references:
|
|
183
|
+
blk = working.get(ref_id)
|
|
184
|
+
if blk is None:
|
|
185
|
+
missing.append(ref_id)
|
|
186
|
+
else:
|
|
187
|
+
out_map[ref_id] = blk
|
|
188
|
+
|
|
189
|
+
for blk in delta.added_blocks:
|
|
190
|
+
out_map[blk.block_id] = blk
|
|
191
|
+
for blk in delta.updated_blocks:
|
|
192
|
+
out_map[blk.block_id] = blk
|
|
193
|
+
|
|
194
|
+
reconstructed = sorted(
|
|
195
|
+
out_map.values(),
|
|
196
|
+
key=lambda b: (-int(b.required), -b.priority, b.block_id),
|
|
197
|
+
)
|
|
198
|
+
return reconstructed, missing
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Agent Evidence Validation and Grounding for RepoDNA v0.11.0.
|
|
2
|
+
|
|
3
|
+
Validates evidence references against:
|
|
4
|
+
- Repository scope (path traversal / workspace escape rejected)
|
|
5
|
+
- Snapshot / revision identity
|
|
6
|
+
- Relative source path & source line range
|
|
7
|
+
- Content hash on disk (staleness detection)
|
|
8
|
+
- Language capability level (PARTIAL when partial static analysis)
|
|
9
|
+
- Secret redaction with explicit redacted_snippet_hash provenance
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from repodna.agent.models import (
|
|
17
|
+
AgentEvidenceReference,
|
|
18
|
+
EvidenceValidationStatus,
|
|
19
|
+
EvidenceVerificationResult,
|
|
20
|
+
FreshnessMetadata,
|
|
21
|
+
)
|
|
22
|
+
from repodna.agent.safety import sanitize_untrusted_text, sha256_short
|
|
23
|
+
from repodna.brain.indexer import SymbolIndexer
|
|
24
|
+
from repodna.schemas.models import LanguageSupportLevel
|
|
25
|
+
from repodna.security.validators import SecurityValidationError, validate_and_resolve_evidence_path
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def verify_agent_evidence(
|
|
29
|
+
evidence_id: str,
|
|
30
|
+
indexer: SymbolIndexer,
|
|
31
|
+
repo_id: str,
|
|
32
|
+
repository_name: str,
|
|
33
|
+
snapshot_id: str,
|
|
34
|
+
repo_root: Path | None = None,
|
|
35
|
+
expected_snapshot_id: str | None = None,
|
|
36
|
+
) -> EvidenceVerificationResult:
|
|
37
|
+
"""Verifies a single evidence ID against the ledger, snapshot, and disk."""
|
|
38
|
+
freshness = FreshnessMetadata(
|
|
39
|
+
repo_id=repo_id,
|
|
40
|
+
repository=repository_name,
|
|
41
|
+
snapshot_id=snapshot_id,
|
|
42
|
+
revision=indexer.revision or "WORKING_TREE",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
clean_id = (evidence_id or "").strip()
|
|
46
|
+
if not clean_id or len(clean_id) > 128:
|
|
47
|
+
return EvidenceVerificationResult(
|
|
48
|
+
evidence_id=clean_id,
|
|
49
|
+
status=EvidenceValidationStatus.INVALID,
|
|
50
|
+
freshness=freshness,
|
|
51
|
+
details="Evidence ID is empty or exceeds maximum valid length.",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if expected_snapshot_id and expected_snapshot_id != snapshot_id:
|
|
55
|
+
return EvidenceVerificationResult(
|
|
56
|
+
evidence_id=clean_id,
|
|
57
|
+
status=EvidenceValidationStatus.STALE,
|
|
58
|
+
freshness=freshness,
|
|
59
|
+
details=(
|
|
60
|
+
f"Evidence belongs to snapshot '{expected_snapshot_id}', which does not match "
|
|
61
|
+
f"current snapshot '{snapshot_id}'."
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
ev = indexer.ledger.get_by_id(clean_id)
|
|
66
|
+
if ev is None:
|
|
67
|
+
return EvidenceVerificationResult(
|
|
68
|
+
evidence_id=clean_id,
|
|
69
|
+
status=EvidenceValidationStatus.UNAVAILABLE,
|
|
70
|
+
freshness=freshness,
|
|
71
|
+
details=f"Evidence ID '{clean_id}' was not found in the current snapshot ledger.",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
status = EvidenceValidationStatus.VERIFIED
|
|
75
|
+
details = "Evidence range and content hash verified against current repository state."
|
|
76
|
+
|
|
77
|
+
if repo_root is not None:
|
|
78
|
+
try:
|
|
79
|
+
resolved, _ = validate_and_resolve_evidence_path(repo_root, ev.file_path)
|
|
80
|
+
if not resolved.exists():
|
|
81
|
+
status = EvidenceValidationStatus.UNAVAILABLE
|
|
82
|
+
details = f"Source file '{ev.file_path}' no longer exists on disk."
|
|
83
|
+
else:
|
|
84
|
+
disk_text = resolved.read_text(encoding="utf-8", errors="replace")
|
|
85
|
+
indexer.ledger.check_staleness(ev.file_path, disk_text, indexer.revision)
|
|
86
|
+
if ev.is_stale:
|
|
87
|
+
status = EvidenceValidationStatus.STALE
|
|
88
|
+
details = f"Evidence is STALE ({ev.staleness_reason.value}): {ev.staleness_details}"
|
|
89
|
+
except SecurityValidationError as exc:
|
|
90
|
+
return EvidenceVerificationResult(
|
|
91
|
+
evidence_id=clean_id,
|
|
92
|
+
status=EvidenceValidationStatus.INVALID,
|
|
93
|
+
freshness=freshness,
|
|
94
|
+
details=f"Security validation failed for evidence path: {exc.message}",
|
|
95
|
+
)
|
|
96
|
+
except OSError as exc:
|
|
97
|
+
status = EvidenceValidationStatus.UNAVAILABLE
|
|
98
|
+
details = f"Unable to read source file '{ev.file_path}': {exc}"
|
|
99
|
+
|
|
100
|
+
if status == EvidenceValidationStatus.VERIFIED and ev.support_level == LanguageSupportLevel.PARTIAL_STATIC:
|
|
101
|
+
status = EvidenceValidationStatus.PARTIAL
|
|
102
|
+
details = "Source snippet verified, but language uses partial static analysis (not full AST)."
|
|
103
|
+
|
|
104
|
+
safe_snip, sec_count, _ = sanitize_untrusted_text(ev.code_snippet or "")
|
|
105
|
+
was_redacted = sec_count > 0 or "[REDACTED:" in safe_snip
|
|
106
|
+
redacted_hash = sha256_short(safe_snip, 16) if was_redacted else None
|
|
107
|
+
|
|
108
|
+
ref = AgentEvidenceReference(
|
|
109
|
+
evidence_id=ev.evidence_id,
|
|
110
|
+
repo_id=repo_id,
|
|
111
|
+
snapshot_id=snapshot_id,
|
|
112
|
+
revision=ev.repository_revision,
|
|
113
|
+
file_path=ev.file_path,
|
|
114
|
+
line_start=ev.line_start,
|
|
115
|
+
line_end=ev.line_end,
|
|
116
|
+
evidence_type=ev.evidence_type.value,
|
|
117
|
+
symbol_name=ev.symbol_name,
|
|
118
|
+
content_hash=ev.content_hash or "",
|
|
119
|
+
redacted=sec_count > 0 or "[REDACTED:" in safe_snip,
|
|
120
|
+
redacted_snippet_hash=redacted_hash,
|
|
121
|
+
snippet=safe_snip,
|
|
122
|
+
capability_level=ev.support_level.value,
|
|
123
|
+
status=status,
|
|
124
|
+
staleness_reason=ev.staleness_reason.value,
|
|
125
|
+
confidence_reason=ev.confidence_reason,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return EvidenceVerificationResult(
|
|
129
|
+
evidence_id=clean_id,
|
|
130
|
+
status=status,
|
|
131
|
+
freshness=freshness,
|
|
132
|
+
evidence=ref,
|
|
133
|
+
details=details,
|
|
134
|
+
)
|