dandelion-memory 1.0.0rc15__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.
- benchmarks/__init__.py +3 -0
- benchmarks/adapters/__init__.py +29 -0
- benchmarks/adapters/ablations.py +406 -0
- benchmarks/adapters/base.py +72 -0
- benchmarks/adapters/controlled/__init__.py +13 -0
- benchmarks/adapters/controlled/core_archival.py +115 -0
- benchmarks/adapters/controlled/extract_resolve.py +130 -0
- benchmarks/adapters/controlled/hybrid_rag.py +120 -0
- benchmarks/adapters/controlled/no_late_binding.py +113 -0
- benchmarks/adapters/dandelion.py +94 -0
- benchmarks/adapters/native/__init__.py +31 -0
- benchmarks/adapters/native/base.py +45 -0
- benchmarks/adapters/native/dandelion_native.py +164 -0
- benchmarks/adapters/native/dandelion_native_b0.py +165 -0
- benchmarks/adapters/native/dandelion_native_b1.py +170 -0
- benchmarks/adapters/native/dandelion_native_b2.py +169 -0
- benchmarks/adapters/native/dandelion_native_b3.py +171 -0
- benchmarks/adapters/native/dandelion_native_c4.py +261 -0
- benchmarks/adapters/native/dandelion_native_c4_1.py +281 -0
- benchmarks/adapters/native/dandelion_native_c4_2.py +435 -0
- benchmarks/adapters/native/event_evidence_b2.py +616 -0
- benchmarks/adapters/native/evidence_b2.py +609 -0
- benchmarks/adapters/native/letta_native.py +253 -0
- benchmarks/adapters/native/mem0_native.py +219 -0
- benchmarks/adapters/native/store_vector_b0.py +792 -0
- benchmarks/adapters/native/store_vector_b2.py +808 -0
- benchmarks/agent_adapter_stdio_acceptance.py +86 -0
- benchmarks/bootstrap_cross_stack.py +218 -0
- benchmarks/canonical_profile_instrumentation.py +167 -0
- benchmarks/canonical_public_baseline.py +288 -0
- benchmarks/cli.py +525 -0
- benchmarks/collector_public30_offline.py +1653 -0
- benchmarks/datasets/__init__.py +45 -0
- benchmarks/datasets/conversational_generator.py +238 -0
- benchmarks/datasets/generator.py +283 -0
- benchmarks/datasets/holdout_topology_generator.py +290 -0
- benchmarks/datasets/holdout_topology_generator_v2.py +294 -0
- benchmarks/datasets/multi_world.py +1643 -0
- benchmarks/datasets/scale_generator.py +289 -0
- benchmarks/datasets/schema.py +57 -0
- benchmarks/deep_collision_stress.py +199 -0
- benchmarks/evaluators/__init__.py +12 -0
- benchmarks/evaluators/manifest.py +142 -0
- benchmarks/evaluators/metrics.py +277 -0
- benchmarks/evaluators/runner.py +258 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v1.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v2.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v3.py +146 -0
- benchmarks/f1_step0/build_ledger.py +143 -0
- benchmarks/f1_step0/build_ledger_v2.py +296 -0
- benchmarks/f1_step0/compare_dev52_readiness_v1.py +106 -0
- benchmarks/f1_step0/locator_public_smoke.py +172 -0
- benchmarks/f1_step0/prepare_dev52_owner_v1.py +133 -0
- benchmarks/f1_step0/prepare_dev52_owner_v2.py +133 -0
- benchmarks/f1_step0/public_identity_probe.py +191 -0
- benchmarks/f1_step0/public_response_mapper.py +101 -0
- benchmarks/f1_step0/real_source_public_preflight.py +244 -0
- benchmarks/f1_step0/run_exact_fusion_dev_experiment_v1.py +83 -0
- benchmarks/f1_step0/scorer.py +110 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v1.py +627 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v2.py +659 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v3.py +776 -0
- benchmarks/f1_step0/test_public_response_mapper.py +110 -0
- benchmarks/f1_step0/test_real_source_public_preflight.py +25 -0
- benchmarks/f1_step0/test_scorer.py +158 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement.py +189 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v2.py +263 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v3.py +334 -0
- benchmarks/f1_step0/typed_readback_public_smoke.py +181 -0
- benchmarks/forensic_c4_1_dev.py +258 -0
- benchmarks/forensic_c4_dev.py +255 -0
- benchmarks/forensic_deep25_c4_1.py +478 -0
- benchmarks/legacy_migration_acceptance.py +29 -0
- benchmarks/longmemeval_actor.py +497 -0
- benchmarks/longmemeval_agent_judge.py +593 -0
- benchmarks/longmemeval_budget.py +139 -0
- benchmarks/longmemeval_full.py +410 -0
- benchmarks/longmemeval_judge.py +327 -0
- benchmarks/longmemeval_pilot.py +316 -0
- benchmarks/longmemeval_s.py +318 -0
- benchmarks/memory_bench.py +248 -0
- benchmarks/memory_formation/__init__.py +1 -0
- benchmarks/memory_formation/audit.py +801 -0
- benchmarks/memory_formation/real_audit.py +688 -0
- benchmarks/memory_session_acceptance.py +279 -0
- benchmarks/native_codex_host.py +513 -0
- benchmarks/owner_dense_acceptance.py +126 -0
- benchmarks/pilot_seeker_vault.py +266 -0
- benchmarks/prepare_public30_ripgrep_range_owner.py +115 -0
- benchmarks/profile_canonical.py +373 -0
- benchmarks/profile_canonical_lanes.py +405 -0
- benchmarks/profile_search_chunks.py +351 -0
- benchmarks/public_ranges_faq_proof.py +121 -0
- benchmarks/public_repos/build_history_scope_v3.py +330 -0
- benchmarks/public_repos/build_oracle.py +108 -0
- benchmarks/public_repos/build_oracle_v2.py +169 -0
- benchmarks/public_repos/build_oracle_v3.py +176 -0
- benchmarks/public_repos/map_public_v2.py +296 -0
- benchmarks/public_repos/project_prompts_v2.py +31 -0
- benchmarks/public_repos/project_prompts_v3.py +29 -0
- benchmarks/public_repos/ready_admin_v2.py +214 -0
- benchmarks/public_repos/score_public_v2.py +258 -0
- benchmarks/public_repos/test_map_public_v2.py +171 -0
- benchmarks/public_repos/test_public_repo_v2.py +44 -0
- benchmarks/public_repos/test_public_repo_v3.py +46 -0
- benchmarks/public_repos/test_ready_admin_v2.py +117 -0
- benchmarks/public_repos/test_score_public_v2.py +163 -0
- benchmarks/public_repos/test_wire_v2.py +292 -0
- benchmarks/public_repos/wire_v2.py +603 -0
- benchmarks/real_blocker_fix_acceptance.py +155 -0
- benchmarks/real_scan_rescan_acceptance.py +41 -0
- benchmarks/recall_v2_20k_smoke.py +112 -0
- benchmarks/recall_v2_e1_retrieve.py +70 -0
- benchmarks/recall_v2_e1_score.py +271 -0
- benchmarks/recall_v2_e2_prepare.py +69 -0
- benchmarks/recall_v2_e2_public_score.py +91 -0
- benchmarks/recall_v2_e2_score.py +108 -0
- benchmarks/recall_v2_navigation_mcp_replay.py +308 -0
- benchmarks/recall_v2_reader_capture.py +118 -0
- benchmarks/recall_v2_reader_replay.py +136 -0
- benchmarks/run_blind_h10_holdout.py +284 -0
- benchmarks/run_blind_h9_holdout.py +275 -0
- benchmarks/run_c4_2_nightly_scale.py +446 -0
- benchmarks/run_context_scale_simulation.py +189 -0
- benchmarks/run_conversational_bench.py +170 -0
- benchmarks/run_h11_evaluation.py +316 -0
- benchmarks/run_h11_v2_evaluation.py +431 -0
- benchmarks/run_native_fixed12.py +469 -0
- benchmarks/run_native_preflight.py +280 -0
- benchmarks/run_scale_stress.py +225 -0
- benchmarks/solanazation_brownfield_01/build_oracle.py +970 -0
- benchmarks/solanazation_brownfield_01/check_level_a.py +78 -0
- benchmarks/solanazation_brownfield_01/debug_scope.py +13 -0
- benchmarks/solanazation_brownfield_01/evaluate_bootstrap_02.py +570 -0
- benchmarks/solanazation_brownfield_01/evaluate_first_pass.py +306 -0
- benchmarks/solanazation_brownfield_01/generate_dryrun_report.py +222 -0
- benchmarks/solanazation_brownfield_01/generate_manifests.py +146 -0
- benchmarks/solanazation_brownfield_01/inspect_misses.py +29 -0
- benchmarks/solanazation_brownfield_01/run_miss_forensic.py +206 -0
- benchmarks/solanazation_brownfield_01/test_facts.py +15 -0
- benchmarks/statistics/__init__.py +15 -0
- benchmarks/statistics/significance.py +326 -0
- benchmarks/test_native_mcp_preflight.py +229 -0
- benchmarks/test_prepare_public30_range_owner.py +35 -0
- benchmarks/test_public30_source_reference.py +698 -0
- benchmarks/test_recall_v2_e1_reader_input.py +89 -0
- benchmarks/test_recall_v2_navigation_mcp_replay.py +155 -0
- benchmarks/test_recall_v2_reader_replay.py +41 -0
- dandelion/__init__.py +3 -0
- dandelion/__main__.py +11 -0
- dandelion/agent_adapter.py +2369 -0
- dandelion/bootstrap/__init__.py +872 -0
- dandelion/bootstrap/alias_policy.py +50 -0
- dandelion/bootstrap/authority.py +225 -0
- dandelion/bootstrap/canonical_history.py +412 -0
- dandelion/bootstrap/classifier.py +403 -0
- dandelion/bootstrap/component_graph.py +280 -0
- dandelion/bootstrap/discovery.py +279 -0
- dandelion/bootstrap/domain_induction.py +180 -0
- dandelion/bootstrap/domain_topology.py +673 -0
- dandelion/bootstrap/evidence_envelope.py +132 -0
- dandelion/bootstrap/extractors/base.py +171 -0
- dandelion/bootstrap/extractors/exact.py +1234 -0
- dandelion/bootstrap/extractors/generic.py +100 -0
- dandelion/bootstrap/extractors/git_temporal.py +111 -0
- dandelion/bootstrap/extractors/registry.py +345 -0
- dandelion/bootstrap/extractors/relations.py +89 -0
- dandelion/bootstrap/extractors/semantic.py +424 -0
- dandelion/bootstrap/extractors/status.py +218 -0
- dandelion/bootstrap/git_sweeper.py +135 -0
- dandelion/bootstrap/manifest.py +246 -0
- dandelion/bootstrap/quarantine.py +264 -0
- dandelion/bootstrap/report.py +259 -0
- dandelion/bootstrap/root_resolver.py +221 -0
- dandelion/bootstrap/tech_profiler.py +125 -0
- dandelion/bootstrap/topology.py +75 -0
- dandelion/bootstrap/topology_index.py +110 -0
- dandelion/bootstrap/transaction.py +315 -0
- dandelion/canonical_bootstrap.py +257 -0
- dandelion/canonical_memory.py +4130 -0
- dandelion/captured_input.py +295 -0
- dandelion/cli.py +767 -0
- dandelion/config.py +40 -0
- dandelion/derived_index.py +745 -0
- dandelion/domains.py +706 -0
- dandelion/embedder.py +229 -0
- dandelion/event_evidence.py +571 -0
- dandelion/evidence.py +812 -0
- dandelion/evidence_response.py +453 -0
- dandelion/evidence_workspace.py +2360 -0
- dandelion/exact_context.py +129 -0
- dandelion/hydrator.py +124 -0
- dandelion/inspector.py +442 -0
- dandelion/inspector_assets/dandelion-mark.svg +33 -0
- dandelion/inspector_assets/dandelion_graph.js +361 -0
- dandelion/inspector_assets/inspector.css +223 -0
- dandelion/inspector_assets/inspector.html +135 -0
- dandelion/inspector_assets/inspector.js +1059 -0
- dandelion/legacy_import.py +431 -0
- dandelion/live_source_grants.py +133 -0
- dandelion/local_owner.py +114 -0
- dandelion/memory_client.py +252 -0
- dandelion/memory_contract.py +107 -0
- dandelion/memory_owner.py +560 -0
- dandelion/reader_providers.py +118 -0
- dandelion/recall_v2.py +767 -0
- dandelion/reconciler.py +219 -0
- dandelion/request_budget.py +125 -0
- dandelion/retained_basis.py +223 -0
- dandelion/retrieval.py +485 -0
- dandelion/router.py +405 -0
- dandelion/search_terms.py +53 -0
- dandelion/security.py +124 -0
- dandelion/server.py +810 -0
- dandelion/source_content_fts.py +219 -0
- dandelion/source_delivery.py +89 -0
- dandelion/source_history.py +241 -0
- dandelion/source_identity.py +88 -0
- dandelion/source_navigator.py +5 -0
- dandelion/source_reader.py +444 -0
- dandelion/source_references.py +379 -0
- dandelion/source_sections.py +265 -0
- dandelion/store_kv.py +684 -0
- dandelion/store_vector.py +1289 -0
- dandelion/studio.py +325 -0
- dandelion/wal.py +227 -0
- dandelion_memory-1.0.0rc15.dist-info/METADATA +48 -0
- dandelion_memory-1.0.0rc15.dist-info/RECORD +232 -0
- dandelion_memory-1.0.0rc15.dist-info/WHEEL +5 -0
- dandelion_memory-1.0.0rc15.dist-info/entry_points.txt +5 -0
- dandelion_memory-1.0.0rc15.dist-info/licenses/LICENSE +21 -0
- dandelion_memory-1.0.0rc15.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""High-confidence routing alias policy for assimilated projects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dandelion.bootstrap.component_graph import ComponentGraph
|
|
9
|
+
from dandelion.bootstrap.root_resolver import RootResolutionResult
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
_GENERIC_COMPONENT_NAMES = {
|
|
13
|
+
"app", "apps", "src", "source", "sources", "lib", "libs", "test", "tests",
|
|
14
|
+
"config", "configs", "docs", "documentation", "build", "dist", "assets",
|
|
15
|
+
"scripts", "tools", "packages", "services", "modules", "core", "shared",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_generic_component_name(value: str) -> bool:
|
|
20
|
+
return value.strip().lower() in _GENERIC_COMPONENT_NAMES
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _variants(value: str) -> set[str]:
|
|
24
|
+
clean = value.strip().lower()
|
|
25
|
+
if len(clean) < 3:
|
|
26
|
+
return set()
|
|
27
|
+
return {
|
|
28
|
+
clean,
|
|
29
|
+
clean.replace("_", "-"),
|
|
30
|
+
clean.replace("-", "_"),
|
|
31
|
+
re.sub(r"[_\-]+", " ", clean),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def routing_aliases(
|
|
36
|
+
root_res: RootResolutionResult,
|
|
37
|
+
workspace_root: Path,
|
|
38
|
+
graph: ComponentGraph,
|
|
39
|
+
) -> list[str]:
|
|
40
|
+
"""Return aliases backed only by the resolved project identity.
|
|
41
|
+
|
|
42
|
+
Component names remain partition-local graph evidence. Promoting even an
|
|
43
|
+
explicit boundary such as ``api`` or ``worker`` into this global registry
|
|
44
|
+
would let one project capture another project's query scope.
|
|
45
|
+
"""
|
|
46
|
+
del graph # Kept in the public signature for bootstrap policy evolution.
|
|
47
|
+
aliases = _variants(root_res.project_name) | _variants(root_res.canonical_id)
|
|
48
|
+
aliases |= _variants(workspace_root.name)
|
|
49
|
+
|
|
50
|
+
return sorted(alias for alias in aliases if alias and alias not in _GENERIC_COMPONENT_NAMES)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""Source authority, context-aware arbitration and conflict handling (BOOTSTRAP-02).
|
|
2
|
+
|
|
3
|
+
Delineates extraction confidence (parser accuracy) from source authority (contextual trustworthiness).
|
|
4
|
+
Implements Section 17: Source authority is not globally fixed (code > docs is not universal).
|
|
5
|
+
For build settings, build config is authoritative.
|
|
6
|
+
For architecture rationale, ADR is authoritative.
|
|
7
|
+
For schemas, migration is authoritative.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import enum
|
|
13
|
+
import time
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Any, Optional
|
|
16
|
+
|
|
17
|
+
from dandelion.bootstrap.evidence_envelope import EvidenceEnvelope
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SourceAuthority(str, enum.Enum):
|
|
21
|
+
"""Hierarchy of configuration source trustworthiness.
|
|
22
|
+
|
|
23
|
+
Higher rank numbers indicate higher baseline authority.
|
|
24
|
+
"""
|
|
25
|
+
RUNTIME_OBSERVED = "RUNTIME_OBSERVED" # Rank 7: Live telemetry or runtime observation
|
|
26
|
+
DEPLOYMENT_CONFIG = "DEPLOYMENT_CONFIG" # Rank 6: Production deployment (k8s, helm, docker-compose.prod)
|
|
27
|
+
PROD_CONFIG = "PROD_CONFIG" # Rank 5: Production settings (production.yaml, config.prod.json)
|
|
28
|
+
BUILD_CONFIG = "BUILD_CONFIG" # Rank 4.5: Build manifests (build.gradle.kts, export_presets.cfg)
|
|
29
|
+
SCHEMA_MIGRATION = "SCHEMA_MIGRATION" # Rank 4.2: Database migrations and formal schemas
|
|
30
|
+
DEV_CONFIG = "DEV_CONFIG" # Rank 4: Local development configurations (dev.env, docker-compose)
|
|
31
|
+
SOURCE_IMPLEMENTATION = "SOURCE_IMPLEMENTATION"# Rank 3.5: Concrete code definitions
|
|
32
|
+
ADR_DECISION = "ADR_DECISION" # Rank 3: Architectural Decision Records
|
|
33
|
+
DOCS_TECHNICAL = "DOCS_TECHNICAL" # Rank 2.5: Technical documentation / specs
|
|
34
|
+
GIT_HISTORY = "GIT_HISTORY" # Rank 2.2: Historical commit messages / git log
|
|
35
|
+
EXAMPLE_CONFIG = "EXAMPLE_CONFIG" # Rank 2: Template configs (.env.example, sample.conf)
|
|
36
|
+
INFERRED_HEURISTIC = "INFERRED_HEURISTIC" # Rank 1: Heuristic parsing from unstructured prose / comments
|
|
37
|
+
NONE = "NONE" # Rank 0: Unidentified / negative baseline
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def rank(self) -> float:
|
|
41
|
+
ranks = {
|
|
42
|
+
SourceAuthority.RUNTIME_OBSERVED: 7.0,
|
|
43
|
+
SourceAuthority.DEPLOYMENT_CONFIG: 6.0,
|
|
44
|
+
SourceAuthority.PROD_CONFIG: 5.0,
|
|
45
|
+
SourceAuthority.BUILD_CONFIG: 4.5,
|
|
46
|
+
SourceAuthority.SCHEMA_MIGRATION: 4.2,
|
|
47
|
+
SourceAuthority.DEV_CONFIG: 4.0,
|
|
48
|
+
SourceAuthority.SOURCE_IMPLEMENTATION: 3.5,
|
|
49
|
+
SourceAuthority.ADR_DECISION: 3.0,
|
|
50
|
+
SourceAuthority.DOCS_TECHNICAL: 2.5,
|
|
51
|
+
SourceAuthority.GIT_HISTORY: 2.2,
|
|
52
|
+
SourceAuthority.EXAMPLE_CONFIG: 2.0,
|
|
53
|
+
SourceAuthority.INFERRED_HEURISTIC: 1.0,
|
|
54
|
+
SourceAuthority.NONE: 0.0,
|
|
55
|
+
}
|
|
56
|
+
return ranks.get(self, 0.0)
|
|
57
|
+
|
|
58
|
+
def is_strictly_more_authoritative_than(self, other: SourceAuthority) -> bool:
|
|
59
|
+
return self.rank > other.rank
|
|
60
|
+
|
|
61
|
+
def is_equal_authority(self, other: SourceAuthority) -> bool:
|
|
62
|
+
return abs(self.rank - other.rank) < 0.01
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class EpistemicTrustClass(str, enum.Enum):
|
|
66
|
+
"""Epistemic status of an extracted knowledge item."""
|
|
67
|
+
AUTHORITATIVE = "AUTHORITATIVE" # High authority verified source (ranks >= 4.5)
|
|
68
|
+
CORROBORATED = "CORROBORATED" # Corroborated by >= 2 independent sources
|
|
69
|
+
DERIVED = "DERIVED" # Single lower-authority source or heuristic inference
|
|
70
|
+
AMBIGUOUS = "AMBIGUOUS" # Conflict detected between equal-authority sources
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class AuthorityRecord:
|
|
75
|
+
"""Provenance and authority record for an extracted fact or memory."""
|
|
76
|
+
key: str
|
|
77
|
+
value: Any
|
|
78
|
+
source_file: str
|
|
79
|
+
source_authority: SourceAuthority
|
|
80
|
+
extraction_confidence: float = 1.0 # Parser precision [0.0 - 1.0]
|
|
81
|
+
epistemic_class: EpistemicTrustClass = EpistemicTrustClass.DERIVED
|
|
82
|
+
line_number: Optional[int] = None
|
|
83
|
+
commit_sha: Optional[str] = None
|
|
84
|
+
security_class: str = "PUBLIC" # PUBLIC, INTERNAL, CONFIDENTIAL, RESTRICTED, SECRET
|
|
85
|
+
timestamp: float = field(default_factory=time.time)
|
|
86
|
+
provenance: Optional[EvidenceEnvelope] = None
|
|
87
|
+
|
|
88
|
+
def to_dict(self) -> dict:
|
|
89
|
+
return {
|
|
90
|
+
"key": self.key,
|
|
91
|
+
"value": self.value,
|
|
92
|
+
"source_file": self.source_file,
|
|
93
|
+
"source_authority": self.source_authority.value,
|
|
94
|
+
"extraction_confidence": self.extraction_confidence,
|
|
95
|
+
"epistemic_class": self.epistemic_class.value,
|
|
96
|
+
"line_number": self.line_number,
|
|
97
|
+
"commit_sha": self.commit_sha,
|
|
98
|
+
"security_class": self.security_class,
|
|
99
|
+
"timestamp": self.timestamp,
|
|
100
|
+
"provenance": self.provenance.to_dict() if self.provenance else None,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def from_dict(cls, data: dict) -> AuthorityRecord:
|
|
105
|
+
return cls(
|
|
106
|
+
key=data["key"],
|
|
107
|
+
value=data["value"],
|
|
108
|
+
source_file=data.get("source_file", ""),
|
|
109
|
+
source_authority=SourceAuthority(data.get("source_authority", SourceAuthority.INFERRED_HEURISTIC.value)),
|
|
110
|
+
extraction_confidence=float(data.get("extraction_confidence", 1.0)),
|
|
111
|
+
epistemic_class=EpistemicTrustClass(data.get("epistemic_class", EpistemicTrustClass.DERIVED.value)),
|
|
112
|
+
line_number=data.get("line_number"),
|
|
113
|
+
commit_sha=data.get("commit_sha"),
|
|
114
|
+
security_class=data.get("security_class", "PUBLIC"),
|
|
115
|
+
timestamp=float(data.get("timestamp", time.time())),
|
|
116
|
+
provenance=(
|
|
117
|
+
EvidenceEnvelope.from_dict(data["provenance"])
|
|
118
|
+
if data.get("provenance") else None
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class ContextAwareAuthorityResolver:
|
|
124
|
+
"""Computes dynamic context-aware authority (BOOTSTRAP-02 Section 17).
|
|
125
|
+
|
|
126
|
+
Evaluates:
|
|
127
|
+
- fact_type (e.g. build_target, schema_field, architecture_decision, runtime_port)
|
|
128
|
+
- source_role (BUILD_CONFIG, ADR, SOURCE_CODE, DOCS)
|
|
129
|
+
- file path context
|
|
130
|
+
"""
|
|
131
|
+
@staticmethod
|
|
132
|
+
def resolve_authority(
|
|
133
|
+
fact_type: str,
|
|
134
|
+
file_role: str,
|
|
135
|
+
rel_path: str,
|
|
136
|
+
default_auth: SourceAuthority = SourceAuthority.PROD_CONFIG,
|
|
137
|
+
) -> SourceAuthority:
|
|
138
|
+
rel_lower = rel_path.lower()
|
|
139
|
+
|
|
140
|
+
# Example/mock/fixture evidence must never define current production
|
|
141
|
+
# state, regardless of the syntax used by the file.
|
|
142
|
+
path_segments = {segment for segment in rel_lower.replace("\\", "/").split("/") if segment}
|
|
143
|
+
if path_segments & {"example", "examples", "fixture", "fixtures", "mock", "mocks", "sample", "samples"}:
|
|
144
|
+
return SourceAuthority.EXAMPLE_CONFIG
|
|
145
|
+
|
|
146
|
+
# Universal roles take precedence over technology or filename hints.
|
|
147
|
+
if file_role in ("deployment", "ci_cd"):
|
|
148
|
+
return SourceAuthority.DEPLOYMENT_CONFIG
|
|
149
|
+
if file_role in ("schema", "migration"):
|
|
150
|
+
return SourceAuthority.SCHEMA_MIGRATION
|
|
151
|
+
|
|
152
|
+
# Build settings: build configs & descriptors have top authority
|
|
153
|
+
if any(bt in fact_type for bt in ("build", "target", "sdk", "compiler", "version_code", "package_id")):
|
|
154
|
+
if file_role in ("build_config", "project_descriptor"):
|
|
155
|
+
return SourceAuthority.BUILD_CONFIG
|
|
156
|
+
if file_role == "source_code":
|
|
157
|
+
return SourceAuthority.SOURCE_IMPLEMENTATION
|
|
158
|
+
|
|
159
|
+
# Schema & data models: migrations/schemas have top authority
|
|
160
|
+
if any(st in fact_type for st in ("schema", "table", "column", "entity", "migration")):
|
|
161
|
+
if file_role in ("schema", "migration"):
|
|
162
|
+
return SourceAuthority.SCHEMA_MIGRATION
|
|
163
|
+
if file_role == "source_code":
|
|
164
|
+
return SourceAuthority.SOURCE_IMPLEMENTATION
|
|
165
|
+
|
|
166
|
+
# Architecture & rationale: ADRs have top authority
|
|
167
|
+
if any(at in fact_type for at in ("rationale", "decision", "tradeoff", "architecture")):
|
|
168
|
+
if "adr" in rel_lower or "/decisions/" in rel_lower:
|
|
169
|
+
return SourceAuthority.ADR_DECISION
|
|
170
|
+
if file_role == "documentation":
|
|
171
|
+
return SourceAuthority.DOCS_TECHNICAL
|
|
172
|
+
|
|
173
|
+
# Deployment & infra
|
|
174
|
+
if file_role in ("build_config", "project_descriptor"):
|
|
175
|
+
return SourceAuthority.BUILD_CONFIG
|
|
176
|
+
|
|
177
|
+
# Source code definitions
|
|
178
|
+
if file_role == "source_code":
|
|
179
|
+
return SourceAuthority.SOURCE_IMPLEMENTATION
|
|
180
|
+
|
|
181
|
+
# Technical documentation
|
|
182
|
+
if file_role == "documentation":
|
|
183
|
+
return SourceAuthority.DOCS_TECHNICAL
|
|
184
|
+
|
|
185
|
+
return default_auth
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def arbitrate_fact_conflict(
|
|
189
|
+
existing: AuthorityRecord,
|
|
190
|
+
candidate: AuthorityRecord,
|
|
191
|
+
) -> tuple[Optional[AuthorityRecord], Optional[str]]:
|
|
192
|
+
"""Arbitrate between existing fact state and incoming candidate.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
(winner_record, conflict_reason)
|
|
196
|
+
If candidate wins: (candidate, None)
|
|
197
|
+
If existing stays unchanged: (existing, None)
|
|
198
|
+
If conflict between equal-authority sources with differing values:
|
|
199
|
+
(None, conflict_description) -> triggers AMBIGUOUS quarantine!
|
|
200
|
+
"""
|
|
201
|
+
# 1. Identical value -> corroborate
|
|
202
|
+
if str(existing.value).strip() == str(candidate.value).strip():
|
|
203
|
+
promoted = EpistemicTrustClass.CORROBORATED
|
|
204
|
+
if existing.source_authority.rank >= SourceAuthority.BUILD_CONFIG.rank:
|
|
205
|
+
promoted = EpistemicTrustClass.AUTHORITATIVE
|
|
206
|
+
candidate.epistemic_class = promoted
|
|
207
|
+
return candidate, None
|
|
208
|
+
|
|
209
|
+
# 2. Candidate has strictly higher authority -> candidate wins
|
|
210
|
+
if candidate.source_authority.is_strictly_more_authoritative_than(existing.source_authority):
|
|
211
|
+
if candidate.source_authority.rank >= SourceAuthority.BUILD_CONFIG.rank:
|
|
212
|
+
candidate.epistemic_class = EpistemicTrustClass.AUTHORITATIVE
|
|
213
|
+
return candidate, None
|
|
214
|
+
|
|
215
|
+
# 3. Existing has strictly higher authority -> existing stays
|
|
216
|
+
if existing.source_authority.is_strictly_more_authoritative_than(candidate.source_authority):
|
|
217
|
+
return existing, None
|
|
218
|
+
|
|
219
|
+
# 4. Equal authority, but conflicting values!
|
|
220
|
+
conflict_desc = (
|
|
221
|
+
f"Conflicting values for key '{existing.key}': "
|
|
222
|
+
f"'{existing.value}' ({existing.source_file}:{existing.source_authority.value}) vs "
|
|
223
|
+
f"'{candidate.value}' ({candidate.source_file}:{candidate.source_authority.value})"
|
|
224
|
+
)
|
|
225
|
+
return None, conflict_desc
|