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,259 @@
|
|
|
1
|
+
"""Introspection Artifact Generator & Assimilation Report (BOOTSTRAP-02 Section 50-51).
|
|
2
|
+
|
|
3
|
+
Generates and persists persistent artifacts into .dandelion/:
|
|
4
|
+
- bootstrap_inventory.json
|
|
5
|
+
- technology_profile.json
|
|
6
|
+
- component_graph.json
|
|
7
|
+
- domain_topology.json
|
|
8
|
+
- exact_candidates.json
|
|
9
|
+
- semantic_candidates.json
|
|
10
|
+
- status_evidence.json
|
|
11
|
+
- conflicts.json
|
|
12
|
+
- quarantine.json
|
|
13
|
+
- history_index.json
|
|
14
|
+
- assimilation_report.json
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import tempfile
|
|
23
|
+
from dataclasses import dataclass, field
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any, Optional
|
|
26
|
+
|
|
27
|
+
from dandelion.bootstrap.authority import AuthorityRecord
|
|
28
|
+
from dandelion.bootstrap.component_graph import ComponentGraph
|
|
29
|
+
from dandelion.bootstrap.discovery import ProjectDiscoveryReport
|
|
30
|
+
from dandelion.bootstrap.domain_induction import InducedDomain
|
|
31
|
+
from dandelion.bootstrap.extractors.base import SemanticMemoryRecord, StatusEvidenceRecord
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _write_json_atomic(path: Path, value: Any) -> None:
|
|
35
|
+
"""Write one derived artifact without exposing a truncated JSON file."""
|
|
36
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
fd, tmp_name = tempfile.mkstemp(dir=str(path.parent), suffix=".tmp")
|
|
38
|
+
try:
|
|
39
|
+
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
|
40
|
+
json.dump(value, handle, indent=2, ensure_ascii=False)
|
|
41
|
+
handle.flush()
|
|
42
|
+
os.fsync(handle.fileno())
|
|
43
|
+
os.replace(tmp_name, path)
|
|
44
|
+
except BaseException:
|
|
45
|
+
try:
|
|
46
|
+
os.unlink(tmp_name)
|
|
47
|
+
except OSError:
|
|
48
|
+
pass
|
|
49
|
+
raise
|
|
50
|
+
from dandelion.bootstrap.root_resolver import RootResolutionResult
|
|
51
|
+
from dandelion.bootstrap.tech_profiler import TechnologyProfile
|
|
52
|
+
from dandelion.hydrator import is_sensitive_key
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_SECRET_ASSIGNMENT_RE = re.compile(
|
|
56
|
+
r"(?i)\b(api[_\s.-]?key|bearer|password|secret[_\s.-]?key|private[_\s.-]?key|"
|
|
57
|
+
r"access[_\s.-]?token|client[_\s.-]?secret)\s*([=:])\s*([^\s,;]+)"
|
|
58
|
+
)
|
|
59
|
+
_TOKEN_VALUE_RE = re.compile(r"\b(?:sk-|pk_|ghp_|xoxb-|xoxp-|AKIA)[A-Za-z0-9_\-]{8,}\b")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _redact_text(value: str) -> str:
|
|
63
|
+
"""Prevent candidate artifacts from becoming a second secret store."""
|
|
64
|
+
value = _SECRET_ASSIGNMENT_RE.sub(r"\1\2[MASKED]", value)
|
|
65
|
+
return _TOKEN_VALUE_RE.sub("[MASKED]", value)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _safe_exact_record(record: AuthorityRecord) -> dict[str, Any]:
|
|
69
|
+
data = record.to_dict()
|
|
70
|
+
if record.security_class == "SECRET" or is_sensitive_key(record.key):
|
|
71
|
+
data["value"] = "[MASKED]"
|
|
72
|
+
elif isinstance(data.get("value"), str):
|
|
73
|
+
data["value"] = _redact_text(data["value"])
|
|
74
|
+
return data
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _safe_semantic_record(record: SemanticMemoryRecord) -> dict[str, Any]:
|
|
78
|
+
data = record.to_dict()
|
|
79
|
+
data["template"] = _redact_text(data["template"])
|
|
80
|
+
return data
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _safe_conflict_item(item: Any) -> dict[str, Any]:
|
|
84
|
+
"""Serialize quarantine state without exposing candidate secret values."""
|
|
85
|
+
candidate = _safe_exact_record(item.candidate_record)
|
|
86
|
+
existing = _safe_exact_record(item.existing_record) if item.existing_record else None
|
|
87
|
+
sensitive = (
|
|
88
|
+
item.candidate_record.security_class == "SECRET"
|
|
89
|
+
or is_sensitive_key(item.candidate_record.key)
|
|
90
|
+
or (item.existing_record is not None and (
|
|
91
|
+
item.existing_record.security_class == "SECRET" or is_sensitive_key(item.existing_record.key)
|
|
92
|
+
))
|
|
93
|
+
)
|
|
94
|
+
return {
|
|
95
|
+
"item_id": item.item_id,
|
|
96
|
+
"key": item.key,
|
|
97
|
+
"reason": "Sensitive fact conflict." if sensitive else _redact_text(item.reason),
|
|
98
|
+
"candidate_record": candidate,
|
|
99
|
+
"existing_record": existing,
|
|
100
|
+
"created_at": item.created_at,
|
|
101
|
+
"resolved": item.resolved,
|
|
102
|
+
"resolved_at": item.resolved_at,
|
|
103
|
+
"resolved_by": item.resolved_by,
|
|
104
|
+
"resolution_notes": "[MASKED]" if sensitive else _redact_text(item.resolution_notes),
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@dataclass
|
|
109
|
+
class AssimilationReport:
|
|
110
|
+
"""Comprehensive assimilation metrics and explanations."""
|
|
111
|
+
project_name: str
|
|
112
|
+
workspace_type: str
|
|
113
|
+
total_files_examined: int
|
|
114
|
+
major_components_count: int
|
|
115
|
+
technologies: list[str] = field(default_factory=list)
|
|
116
|
+
exact_facts_count: int = 0
|
|
117
|
+
facts_retired_count: int = 0
|
|
118
|
+
semantic_memories_count: int = 0
|
|
119
|
+
memories_deactivated_count: int = 0
|
|
120
|
+
sources_moved_count: int = 0
|
|
121
|
+
status_records_count: int = 0
|
|
122
|
+
quarantined_conflicts_count: int = 0
|
|
123
|
+
unknown_text_formats_count: int = 0
|
|
124
|
+
sensitive_protected_count: int = 0
|
|
125
|
+
git_commits_indexed: int = 0
|
|
126
|
+
unresolved_components: list[str] = field(default_factory=list)
|
|
127
|
+
topology_revision: int = 0
|
|
128
|
+
topology_changes_count: int = 0
|
|
129
|
+
duration_sec: float = 0.0
|
|
130
|
+
|
|
131
|
+
def to_dict(self) -> dict:
|
|
132
|
+
return {
|
|
133
|
+
"project_name": self.project_name,
|
|
134
|
+
"workspace_type": self.workspace_type,
|
|
135
|
+
"total_files_examined": self.total_files_examined,
|
|
136
|
+
"major_components_count": self.major_components_count,
|
|
137
|
+
"technologies": self.technologies,
|
|
138
|
+
"exact_facts_count": self.exact_facts_count,
|
|
139
|
+
"facts_retired_count": self.facts_retired_count,
|
|
140
|
+
"semantic_memories_count": self.semantic_memories_count,
|
|
141
|
+
"memories_deactivated_count": self.memories_deactivated_count,
|
|
142
|
+
"sources_moved_count": self.sources_moved_count,
|
|
143
|
+
"status_records_count": self.status_records_count,
|
|
144
|
+
"quarantined_conflicts_count": self.quarantined_conflicts_count,
|
|
145
|
+
"unknown_text_formats_count": self.unknown_text_formats_count,
|
|
146
|
+
"sensitive_protected_count": self.sensitive_protected_count,
|
|
147
|
+
"git_commits_indexed": self.git_commits_indexed,
|
|
148
|
+
"unresolved_components": self.unresolved_components,
|
|
149
|
+
"topology_revision": self.topology_revision,
|
|
150
|
+
"topology_changes_count": self.topology_changes_count,
|
|
151
|
+
"duration_sec": round(self.duration_sec, 3),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
def format_human_summary(self) -> str:
|
|
155
|
+
"""Produce the human-readable explanation demanded by Section 51 of ТЗ."""
|
|
156
|
+
lines = [
|
|
157
|
+
"=======================================================",
|
|
158
|
+
"Dandelion BOOTSTRAP-02 Universal Assimilation Report",
|
|
159
|
+
"=======================================================",
|
|
160
|
+
f" Project Identity: {self.project_name} ({self.workspace_type})",
|
|
161
|
+
f" Detected Major Components: {self.major_components_count}",
|
|
162
|
+
f" Technologies Profiled: {', '.join(self.technologies) if self.technologies else 'None'}",
|
|
163
|
+
f" Files Examined: {self.total_files_examined}",
|
|
164
|
+
"-------------------------------------------------------",
|
|
165
|
+
f" Exact Facts Extracted: {self.exact_facts_count}",
|
|
166
|
+
f" Exact Facts Retired: {self.facts_retired_count}",
|
|
167
|
+
f" Semantic Memories Stored: {self.semantic_memories_count}",
|
|
168
|
+
f" Semantic Memories Retired: {self.memories_deactivated_count}",
|
|
169
|
+
f" Sources Moved: {self.sources_moved_count}",
|
|
170
|
+
f" Status Evidence Extracted: {self.status_records_count}",
|
|
171
|
+
f" Conflicts Quarantined: {self.quarantined_conflicts_count}",
|
|
172
|
+
f" Unknown Text Formats: {self.unknown_text_formats_count} (gracefully indexed)",
|
|
173
|
+
f" Sensitive Values: {self.sensitive_protected_count} protected, 0 exposed",
|
|
174
|
+
f" Git History Commits: {self.git_commits_indexed} indexed",
|
|
175
|
+
f" Unresolved Components: {len(self.unresolved_components)}",
|
|
176
|
+
f" Topology Revision: {self.topology_revision}",
|
|
177
|
+
f" Topology Changes: {self.topology_changes_count}",
|
|
178
|
+
f" Duration: {self.duration_sec:.3f}s",
|
|
179
|
+
"=======================================================",
|
|
180
|
+
]
|
|
181
|
+
return "\n".join(lines)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def persist_bootstrap_artifacts(
|
|
185
|
+
dandelion_dir: Path,
|
|
186
|
+
report: ProjectDiscoveryReport,
|
|
187
|
+
root_res: RootResolutionResult,
|
|
188
|
+
tech_profile: TechnologyProfile,
|
|
189
|
+
graph: ComponentGraph,
|
|
190
|
+
induced_domains: list[InducedDomain],
|
|
191
|
+
status_records: list[StatusEvidenceRecord],
|
|
192
|
+
assimilation: AssimilationReport,
|
|
193
|
+
exact_candidates: list[AuthorityRecord],
|
|
194
|
+
semantic_candidates: list[SemanticMemoryRecord],
|
|
195
|
+
conflict_items: list[Any],
|
|
196
|
+
history_records: list[AuthorityRecord],
|
|
197
|
+
topology_snapshot: Optional[dict[str, Any]] = None,
|
|
198
|
+
) -> None:
|
|
199
|
+
"""Save the BOOTSTRAP-02 introspection artifacts into .dandelion/."""
|
|
200
|
+
dandelion_dir.mkdir(parents=True, exist_ok=True)
|
|
201
|
+
|
|
202
|
+
# 1. bootstrap_inventory.json
|
|
203
|
+
_write_json_atomic(dandelion_dir / "bootstrap_inventory.json", report.to_inventory_dict())
|
|
204
|
+
|
|
205
|
+
# 2. technology_profile.json
|
|
206
|
+
_write_json_atomic(dandelion_dir / "technology_profile.json", tech_profile.to_dict())
|
|
207
|
+
|
|
208
|
+
# 3. component_graph.json
|
|
209
|
+
_write_json_atomic(dandelion_dir / "component_graph.json", graph.to_dict())
|
|
210
|
+
|
|
211
|
+
# 4. domain_topology.json
|
|
212
|
+
legacy_partitions = [d.to_dict() for d in induced_domains]
|
|
213
|
+
topo_data = {
|
|
214
|
+
"schema_version": "legacy-2.0.0",
|
|
215
|
+
"partitions_count": len(induced_domains),
|
|
216
|
+
"partitions": legacy_partitions,
|
|
217
|
+
}
|
|
218
|
+
if topology_snapshot is not None:
|
|
219
|
+
topo_data = {
|
|
220
|
+
**topology_snapshot,
|
|
221
|
+
# Keep the old projection readable while runtime placement moves
|
|
222
|
+
# to stable domain IDs and versioned snapshots.
|
|
223
|
+
"partitions_count": len(induced_domains),
|
|
224
|
+
"partitions": legacy_partitions,
|
|
225
|
+
}
|
|
226
|
+
_write_json_atomic(dandelion_dir / "domain_topology.json", topo_data)
|
|
227
|
+
|
|
228
|
+
# 5. status_evidence.json
|
|
229
|
+
status_data = {
|
|
230
|
+
"count": len(status_records),
|
|
231
|
+
"records": [s.to_dict() for s in status_records],
|
|
232
|
+
}
|
|
233
|
+
_write_json_atomic(dandelion_dir / "status_evidence.json", status_data)
|
|
234
|
+
|
|
235
|
+
# 6. Candidate artifacts are diagnostic only; raw secrets are always masked.
|
|
236
|
+
_write_json_atomic(
|
|
237
|
+
dandelion_dir / "exact_candidates.json",
|
|
238
|
+
{"count": len(exact_candidates), "records": [_safe_exact_record(r) for r in exact_candidates]},
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
_write_json_atomic(
|
|
242
|
+
dandelion_dir / "semantic_candidates.json",
|
|
243
|
+
{"count": len(semantic_candidates), "records": [_safe_semantic_record(r) for r in semantic_candidates]},
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
# 7. Conflicts are duplicated from the quarantine ledger for CLI introspection.
|
|
247
|
+
_write_json_atomic(
|
|
248
|
+
dandelion_dir / "conflicts.json",
|
|
249
|
+
{"count": len(conflict_items), "records": [_safe_conflict_item(i) for i in conflict_items]},
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# 8. Historical facts remain temporal evidence, distinct from current state.
|
|
253
|
+
_write_json_atomic(
|
|
254
|
+
dandelion_dir / "history_index.json",
|
|
255
|
+
{"count": len(history_records), "records": [_safe_exact_record(r) for r in history_records]},
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# 9. assimilation_report.json
|
|
259
|
+
_write_json_atomic(dandelion_dir / "assimilation_report.json", assimilation.to_dict())
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"""Universal Root Resolver (BOOTSTRAP-02 Section 5).
|
|
2
|
+
|
|
3
|
+
Determines canonical project identity and workspace boundaries from the totality
|
|
4
|
+
of observed structural evidence, eliminating the failure mode where a nested child
|
|
5
|
+
manifest (e.g. backend/staking/package.json) usurps root identity.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Optional
|
|
16
|
+
|
|
17
|
+
from dandelion.bootstrap.discovery import DiscoveredFile, ProjectDiscoveryReport
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class RootResolutionResult:
|
|
22
|
+
"""Evidence-backed identity of the workspace and root project."""
|
|
23
|
+
project_name: str
|
|
24
|
+
canonical_id: str
|
|
25
|
+
confidence: float
|
|
26
|
+
workspace_type: str # single_project, monorepo, polyglot, nested_application
|
|
27
|
+
evidence: list[str] = field(default_factory=list)
|
|
28
|
+
workspace_boundaries: list[str] = field(default_factory=list)
|
|
29
|
+
|
|
30
|
+
def to_dict(self) -> dict:
|
|
31
|
+
return {
|
|
32
|
+
"project_name": self.project_name,
|
|
33
|
+
"canonical_id": self.canonical_id,
|
|
34
|
+
"confidence": round(self.confidence, 2),
|
|
35
|
+
"workspace_type": self.workspace_type,
|
|
36
|
+
"evidence": self.evidence,
|
|
37
|
+
"workspace_boundaries": self.workspace_boundaries,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _clean_name(name: str) -> str:
|
|
42
|
+
"""Normalize string into canonical alphanumeric identifier."""
|
|
43
|
+
cleaned = re.sub(r"[^\w\-]", "_", name.strip())
|
|
44
|
+
cleaned = re.sub(r"_+", "_", cleaned).strip("_")
|
|
45
|
+
return cleaned.lower() or "unnamed_project"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _workspace_boundaries(report: ProjectDiscoveryReport) -> list[str]:
|
|
49
|
+
"""Return explicit child project roots and nested repository roots.
|
|
50
|
+
|
|
51
|
+
Discovery deliberately skips ``.git`` directories, so nested repositories
|
|
52
|
+
need a small, bounded filesystem check of their own. A child descriptor is
|
|
53
|
+
equally explicit evidence that a directory owns an independently buildable
|
|
54
|
+
component. Both kinds remain paths, not guessed product/domain labels.
|
|
55
|
+
"""
|
|
56
|
+
boundaries = {
|
|
57
|
+
str(Path(manifest.rel_path).parent).replace("\\", "/")
|
|
58
|
+
for manifest in report.manifests
|
|
59
|
+
if Path(manifest.rel_path).parent != Path(".")
|
|
60
|
+
and manifest.role.value == "project_descriptor"
|
|
61
|
+
}
|
|
62
|
+
checked = 0
|
|
63
|
+
for current, dirs, _ in os.walk(report.root_path):
|
|
64
|
+
dirs[:] = [d for d in dirs if d not in {".dandelion", "node_modules", "vendor", "__pycache__"}]
|
|
65
|
+
if ".git" in dirs:
|
|
66
|
+
if current != str(report.root_path):
|
|
67
|
+
boundaries.add(Path(current).relative_to(report.root_path).as_posix())
|
|
68
|
+
dirs.remove(".git")
|
|
69
|
+
checked += 1
|
|
70
|
+
if checked >= 256:
|
|
71
|
+
break
|
|
72
|
+
return sorted(boundary for boundary in boundaries if boundary not in {"", "."})
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _workspace_type(report: ProjectDiscoveryReport, boundaries: list[str], root_workspace: bool = False) -> str:
|
|
76
|
+
if root_workspace or len(boundaries) > 1:
|
|
77
|
+
return "monorepo"
|
|
78
|
+
if len({manifest.format for manifest in report.manifests}) > 1:
|
|
79
|
+
return "polyglot"
|
|
80
|
+
if boundaries:
|
|
81
|
+
return "nested_application"
|
|
82
|
+
return "single_project"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def resolve_project_root(report: ProjectDiscoveryReport) -> RootResolutionResult:
|
|
86
|
+
"""Resolve true workspace identity from multi-signal evidence.
|
|
87
|
+
|
|
88
|
+
Order of Evidence Authority:
|
|
89
|
+
1. Root-level project descriptor (depth == 0) e.g. project.godot, Cargo.toml, pyproject.toml, package.json
|
|
90
|
+
2. Git repository origin / directory name
|
|
91
|
+
3. Monorepo workspace declarations
|
|
92
|
+
4. Child manifest majority / common prefix
|
|
93
|
+
5. Directory fallback
|
|
94
|
+
"""
|
|
95
|
+
root = report.root_path
|
|
96
|
+
dir_name = _clean_name(root.name)
|
|
97
|
+
evidence: list[str] = []
|
|
98
|
+
boundaries = _workspace_boundaries(report)
|
|
99
|
+
if boundaries:
|
|
100
|
+
evidence.append(f"Explicit workspace boundaries: {', '.join(boundaries)}")
|
|
101
|
+
|
|
102
|
+
# 1. Inspect Root-Level Manifests (depth 0 only!)
|
|
103
|
+
root_manifests = [
|
|
104
|
+
m for m in report.manifests
|
|
105
|
+
if "/" not in m.rel_path.replace("\\", "/") and m.rel_path != ""
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
# Priority A: Godot Project Descriptor
|
|
109
|
+
for m in root_manifests:
|
|
110
|
+
if m.format == "godot_project":
|
|
111
|
+
try:
|
|
112
|
+
txt = m.abs_path.read_text(encoding="utf-8", errors="ignore")
|
|
113
|
+
match = re.search(r'config/name\s*=\s*["\']([^"\']+)["\']', txt)
|
|
114
|
+
if match:
|
|
115
|
+
pname = _clean_name(match.group(1))
|
|
116
|
+
evidence.append(f"Root project.godot config/name='{match.group(1)}'")
|
|
117
|
+
return RootResolutionResult(
|
|
118
|
+
project_name=pname,
|
|
119
|
+
canonical_id=pname,
|
|
120
|
+
confidence=0.98,
|
|
121
|
+
workspace_type=_workspace_type(report, boundaries),
|
|
122
|
+
evidence=evidence,
|
|
123
|
+
workspace_boundaries=boundaries,
|
|
124
|
+
)
|
|
125
|
+
except Exception:
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
# Priority B: Python pyproject.toml at root
|
|
129
|
+
for m in root_manifests:
|
|
130
|
+
if m.format == "pyproject":
|
|
131
|
+
try:
|
|
132
|
+
txt = m.abs_path.read_text(encoding="utf-8", errors="ignore")
|
|
133
|
+
match = re.search(r'name\s*=\s*["\']([^"\']+)["\']', txt)
|
|
134
|
+
if match:
|
|
135
|
+
pname = _clean_name(match.group(1))
|
|
136
|
+
evidence.append(f"Root pyproject.toml name='{match.group(1)}'")
|
|
137
|
+
return RootResolutionResult(
|
|
138
|
+
project_name=pname,
|
|
139
|
+
canonical_id=pname,
|
|
140
|
+
confidence=0.98,
|
|
141
|
+
workspace_type=_workspace_type(report, boundaries),
|
|
142
|
+
evidence=evidence,
|
|
143
|
+
workspace_boundaries=boundaries,
|
|
144
|
+
)
|
|
145
|
+
except Exception:
|
|
146
|
+
pass
|
|
147
|
+
|
|
148
|
+
# Priority C: Rust Cargo.toml at root
|
|
149
|
+
for m in root_manifests:
|
|
150
|
+
if m.format == "cargo_manifest":
|
|
151
|
+
try:
|
|
152
|
+
txt = m.abs_path.read_text(encoding="utf-8", errors="ignore")
|
|
153
|
+
match = re.search(r'name\s*=\s*["\']([^"\']+)["\']', txt)
|
|
154
|
+
if match:
|
|
155
|
+
pname = _clean_name(match.group(1))
|
|
156
|
+
evidence.append(f"Root Cargo.toml name='{match.group(1)}'")
|
|
157
|
+
return RootResolutionResult(
|
|
158
|
+
project_name=pname,
|
|
159
|
+
canonical_id=pname,
|
|
160
|
+
confidence=0.98,
|
|
161
|
+
workspace_type=_workspace_type(report, boundaries),
|
|
162
|
+
evidence=evidence,
|
|
163
|
+
workspace_boundaries=boundaries,
|
|
164
|
+
)
|
|
165
|
+
except Exception:
|
|
166
|
+
pass
|
|
167
|
+
|
|
168
|
+
# Priority D: Node.js package.json at root
|
|
169
|
+
for m in root_manifests:
|
|
170
|
+
if m.format == "npm_package":
|
|
171
|
+
try:
|
|
172
|
+
data = json.loads(m.abs_path.read_text(encoding="utf-8", errors="ignore"))
|
|
173
|
+
if "name" in data and data["name"]:
|
|
174
|
+
pname = _clean_name(data["name"])
|
|
175
|
+
is_monorepo = "workspaces" in data
|
|
176
|
+
wtype = _workspace_type(report, boundaries, root_workspace=is_monorepo)
|
|
177
|
+
evidence.append(f"Root package.json name='{data['name']}' (workspaces={is_monorepo})")
|
|
178
|
+
return RootResolutionResult(
|
|
179
|
+
project_name=pname,
|
|
180
|
+
canonical_id=pname,
|
|
181
|
+
confidence=0.95,
|
|
182
|
+
workspace_type=wtype,
|
|
183
|
+
evidence=evidence,
|
|
184
|
+
workspace_boundaries=boundaries,
|
|
185
|
+
)
|
|
186
|
+
except Exception:
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
# 2. Check Git Origin / Remote URL
|
|
190
|
+
if report.is_git_repo:
|
|
191
|
+
git_config = root / ".git" / "config"
|
|
192
|
+
if git_config.exists():
|
|
193
|
+
try:
|
|
194
|
+
txt = git_config.read_text(encoding="utf-8", errors="ignore")
|
|
195
|
+
match = re.search(r'url\s*=\s*.*?/([^/\s]+?)(?:\.git)?\s*$', txt, re.MULTILINE)
|
|
196
|
+
if match:
|
|
197
|
+
git_repo_name = _clean_name(match.group(1))
|
|
198
|
+
evidence.append(f"Git remote origin repository name='{git_repo_name}'")
|
|
199
|
+
return RootResolutionResult(
|
|
200
|
+
project_name=git_repo_name,
|
|
201
|
+
canonical_id=git_repo_name,
|
|
202
|
+
confidence=0.90,
|
|
203
|
+
workspace_type=_workspace_type(report, boundaries),
|
|
204
|
+
evidence=evidence,
|
|
205
|
+
workspace_boundaries=boundaries,
|
|
206
|
+
)
|
|
207
|
+
except Exception:
|
|
208
|
+
pass
|
|
209
|
+
|
|
210
|
+
# 3. Fallback to Directory Name with Multi-Component Awareness
|
|
211
|
+
evidence.append(f"Root filesystem directory name='{dir_name}'")
|
|
212
|
+
wtype = _workspace_type(report, boundaries)
|
|
213
|
+
|
|
214
|
+
return RootResolutionResult(
|
|
215
|
+
project_name=dir_name,
|
|
216
|
+
canonical_id=dir_name,
|
|
217
|
+
confidence=0.80,
|
|
218
|
+
workspace_type=wtype,
|
|
219
|
+
evidence=evidence,
|
|
220
|
+
workspace_boundaries=boundaries,
|
|
221
|
+
)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Technology Profiler (BOOTSTRAP-02 Section 4).
|
|
2
|
+
|
|
3
|
+
Discovers programming languages, runtimes, build tools, frameworks, and datastores.
|
|
4
|
+
CRITICAL INVARIANT: Technology is metadata, NEVER a project domain node.
|
|
5
|
+
Answers: "What technology implements this component?", NOT "What is this component?".
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections import Counter
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from dandelion.bootstrap.discovery import DiscoveredFile, ProjectDiscoveryReport
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class TechnologyProfile:
|
|
20
|
+
"""Multi-layer technology profile for a workspace."""
|
|
21
|
+
primary_language: str
|
|
22
|
+
languages: dict[str, int] = field(default_factory=dict)
|
|
23
|
+
frameworks: list[str] = field(default_factory=list)
|
|
24
|
+
build_tools: list[str] = field(default_factory=list)
|
|
25
|
+
datastores: list[str] = field(default_factory=list)
|
|
26
|
+
infra_tools: list[str] = field(default_factory=list)
|
|
27
|
+
component_technologies: dict[str, list[str]] = field(default_factory=dict)
|
|
28
|
+
|
|
29
|
+
def to_dict(self) -> dict:
|
|
30
|
+
return {
|
|
31
|
+
"primary_language": self.primary_language,
|
|
32
|
+
"languages": self.languages,
|
|
33
|
+
"frameworks": sorted(self.frameworks),
|
|
34
|
+
"build_tools": sorted(self.build_tools),
|
|
35
|
+
"datastores": sorted(self.datastores),
|
|
36
|
+
"infra_tools": sorted(self.infra_tools),
|
|
37
|
+
"component_technologies": self.component_technologies,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def profile_project_technologies(report: ProjectDiscoveryReport) -> TechnologyProfile:
|
|
42
|
+
"""Analyze all discovered artifacts to produce a technology profile."""
|
|
43
|
+
lang_counter: Counter[str] = Counter()
|
|
44
|
+
frameworks: set[str] = set()
|
|
45
|
+
build_tools: set[str] = set()
|
|
46
|
+
datastores: set[str] = set()
|
|
47
|
+
infra_tools: set[str] = set()
|
|
48
|
+
comp_tech: dict[str, set[str]] = {}
|
|
49
|
+
|
|
50
|
+
for f in report.all_discovered:
|
|
51
|
+
fmt = f.format.lower()
|
|
52
|
+
norm = f.rel_path.replace("\\", "/").lower()
|
|
53
|
+
parts = norm.split("/")
|
|
54
|
+
component_key = parts[0] if len(parts) > 1 else "root"
|
|
55
|
+
|
|
56
|
+
if component_key not in comp_tech:
|
|
57
|
+
comp_tech[component_key] = set()
|
|
58
|
+
|
|
59
|
+
# Language tracking
|
|
60
|
+
if f.role.value in ("source_code", "test"):
|
|
61
|
+
lang = fmt.split("_")[0]
|
|
62
|
+
if lang in ("python", "gdscript", "kotlin", "java", "javascript", "typescript", "rust", "go", "c", "cpp", "csharp", "ruby", "shell"):
|
|
63
|
+
lang_counter[lang] += 1
|
|
64
|
+
comp_tech[component_key].add(lang)
|
|
65
|
+
|
|
66
|
+
# Framework & Engine Detection
|
|
67
|
+
if fmt == "godot_project" or norm.endswith(".godot"):
|
|
68
|
+
frameworks.add("Godot 4.x")
|
|
69
|
+
build_tools.add("Godot Export")
|
|
70
|
+
comp_tech[component_key].add("Godot")
|
|
71
|
+
if "react" in norm or fmt in ("javascript_react", "typescript_react"):
|
|
72
|
+
frameworks.add("React")
|
|
73
|
+
comp_tech[component_key].add("React")
|
|
74
|
+
if "vue" in norm:
|
|
75
|
+
frameworks.add("Vue")
|
|
76
|
+
if "fastapi" in norm or "django" in norm or "flask" in norm:
|
|
77
|
+
frameworks.add("Python Web")
|
|
78
|
+
if "express" in norm or (f.format == "npm_package" and "express" in f.abs_path.read_text(encoding="utf-8", errors="ignore")):
|
|
79
|
+
frameworks.add("Express.js")
|
|
80
|
+
comp_tech[component_key].add("Express.js")
|
|
81
|
+
if "solana" in norm or "mwa" in norm or "web3" in norm:
|
|
82
|
+
frameworks.add("Solana MWA")
|
|
83
|
+
comp_tech[component_key].add("Solana Web3")
|
|
84
|
+
|
|
85
|
+
# Build tools
|
|
86
|
+
if "gradle" in fmt:
|
|
87
|
+
build_tools.add("Gradle")
|
|
88
|
+
comp_tech[component_key].add("Gradle")
|
|
89
|
+
if fmt == "npm_package":
|
|
90
|
+
build_tools.add("npm")
|
|
91
|
+
comp_tech[component_key].add("npm")
|
|
92
|
+
if fmt == "pyproject" or "setup.py" in norm:
|
|
93
|
+
build_tools.add("pip / setuptools")
|
|
94
|
+
if fmt == "cargo_manifest":
|
|
95
|
+
build_tools.add("Cargo")
|
|
96
|
+
|
|
97
|
+
# Infra & Deployment
|
|
98
|
+
if "docker" in fmt or "dockerfile" in norm:
|
|
99
|
+
infra_tools.add("Docker")
|
|
100
|
+
if "k8s" in norm or "helm" in norm or "kubernetes" in norm:
|
|
101
|
+
infra_tools.add("Kubernetes")
|
|
102
|
+
if ".github/workflows" in norm:
|
|
103
|
+
infra_tools.add("GitHub Actions")
|
|
104
|
+
if "terraform" in norm or norm.endswith((".tf", ".tfvars")):
|
|
105
|
+
infra_tools.add("Terraform")
|
|
106
|
+
|
|
107
|
+
# Datastores
|
|
108
|
+
if norm.endswith(".sql") or "postgres" in norm:
|
|
109
|
+
datastores.add("PostgreSQL / SQL")
|
|
110
|
+
if "redis" in norm:
|
|
111
|
+
datastores.add("Redis")
|
|
112
|
+
if "sqlite" in norm:
|
|
113
|
+
datastores.add("SQLite")
|
|
114
|
+
|
|
115
|
+
primary_lang = lang_counter.most_common(1)[0][0] if lang_counter else "unknown"
|
|
116
|
+
|
|
117
|
+
return TechnologyProfile(
|
|
118
|
+
primary_language=primary_lang,
|
|
119
|
+
languages=dict(lang_counter),
|
|
120
|
+
frameworks=list(frameworks),
|
|
121
|
+
build_tools=list(build_tools),
|
|
122
|
+
datastores=list(datastores),
|
|
123
|
+
infra_tools=list(infra_tools),
|
|
124
|
+
component_technologies={k: sorted(list(v)) for k, v in comp_tech.items() if v},
|
|
125
|
+
)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Project topology and descriptor-based partition builder (BOOTSTRAP-02).
|
|
2
|
+
|
|
3
|
+
Derives canonical 3-tier topology: project / domain / component, generating
|
|
4
|
+
authoritative partition descriptors for the Partition Router using dynamic
|
|
5
|
+
domain induction from the Component Graph.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import tempfile
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
from dandelion.domains import PartitionDescriptor, PartitionKey
|
|
17
|
+
from dandelion.bootstrap.component_graph import build_component_graph
|
|
18
|
+
from dandelion.bootstrap.discovery import ProjectDiscoveryReport
|
|
19
|
+
from dandelion.bootstrap.domain_induction import induce_domains_from_graph
|
|
20
|
+
from dandelion.bootstrap.root_resolver import resolve_project_root
|
|
21
|
+
from dandelion.bootstrap.tech_profiler import profile_project_technologies
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def build_project_topology(
|
|
25
|
+
report: ProjectDiscoveryReport,
|
|
26
|
+
fallback_project_name: Optional[str] = None,
|
|
27
|
+
) -> list[PartitionDescriptor]:
|
|
28
|
+
"""Derive canonical project partitions and descriptors using dynamic domain induction."""
|
|
29
|
+
# 1. Resolve true workspace root
|
|
30
|
+
root_res = resolve_project_root(report)
|
|
31
|
+
if fallback_project_name:
|
|
32
|
+
root_res.project_name = fallback_project_name
|
|
33
|
+
root_res.canonical_id = fallback_project_name
|
|
34
|
+
|
|
35
|
+
# 2. Build Technology Profile and Component Graph
|
|
36
|
+
tech_profile = profile_project_technologies(report)
|
|
37
|
+
graph = build_component_graph(report, root_res, tech_profile)
|
|
38
|
+
|
|
39
|
+
# 3. Dynamically Induce Domains
|
|
40
|
+
induced_domains = induce_domains_from_graph(graph, root_res)
|
|
41
|
+
|
|
42
|
+
# 4. Convert to PartitionDescriptors
|
|
43
|
+
descriptors = [d.to_partition_descriptor() for d in induced_domains]
|
|
44
|
+
|
|
45
|
+
return descriptors
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def save_topology(descriptors: list[PartitionDescriptor], out_path: Path) -> None:
|
|
49
|
+
"""Persist generated topology descriptors to JSON."""
|
|
50
|
+
data = {
|
|
51
|
+
"version": "1.0.0",
|
|
52
|
+
"partitions_count": len(descriptors),
|
|
53
|
+
"partitions": [d.to_dict() for d in descriptors],
|
|
54
|
+
}
|
|
55
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
56
|
+
fd, tmp_name = tempfile.mkstemp(dir=str(out_path.parent), suffix=".tmp")
|
|
57
|
+
try:
|
|
58
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
59
|
+
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
60
|
+
f.flush()
|
|
61
|
+
os.fsync(f.fileno())
|
|
62
|
+
os.replace(tmp_name, out_path)
|
|
63
|
+
except BaseException:
|
|
64
|
+
try:
|
|
65
|
+
os.unlink(tmp_name)
|
|
66
|
+
except OSError:
|
|
67
|
+
pass
|
|
68
|
+
raise
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def load_topology(topology_file: Path) -> list[PartitionDescriptor]:
|
|
72
|
+
"""Load cached partition descriptors from JSON file."""
|
|
73
|
+
with open(topology_file, "r", encoding="utf-8") as f:
|
|
74
|
+
data = json.load(f)
|
|
75
|
+
return [PartitionDescriptor.from_dict(p) for p in data.get("partitions", [])]
|