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,279 @@
|
|
|
1
|
+
"""Universal project artifact discovery with gitignore awareness (BOOTSTRAP-02).
|
|
2
|
+
|
|
3
|
+
Performs universal content-first discovery across any software repository,
|
|
4
|
+
normalizing all files into DiscoveredFile records with content hashes,
|
|
5
|
+
FileRoles, and context-aware source authority.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import os
|
|
12
|
+
import subprocess
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Optional
|
|
16
|
+
|
|
17
|
+
from dandelion.bootstrap.authority import SourceAuthority
|
|
18
|
+
from dandelion.bootstrap.classifier import (
|
|
19
|
+
ClassificationResult,
|
|
20
|
+
FileRole,
|
|
21
|
+
classify_content,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class DiscoveredFile:
|
|
27
|
+
"""An identified and classified workspace artifact."""
|
|
28
|
+
rel_path: str
|
|
29
|
+
abs_path: Path
|
|
30
|
+
file_type: str # manifest, config, adr, documentation, schema, source, test, unknown
|
|
31
|
+
role: FileRole
|
|
32
|
+
authority: SourceAuthority
|
|
33
|
+
format: str # toml, json, yaml, env, markdown, gdscript, kotlin, python, docker, etc.
|
|
34
|
+
size_bytes: int = 0
|
|
35
|
+
content_hash: str = ""
|
|
36
|
+
is_text: bool = True
|
|
37
|
+
signals: list[str] = field(default_factory=list)
|
|
38
|
+
|
|
39
|
+
def to_dict(self) -> dict:
|
|
40
|
+
return {
|
|
41
|
+
"rel_path": self.rel_path,
|
|
42
|
+
"abs_path": str(self.abs_path),
|
|
43
|
+
"file_type": self.file_type,
|
|
44
|
+
"role": self.role.value,
|
|
45
|
+
"authority": self.authority.value,
|
|
46
|
+
"format": self.format,
|
|
47
|
+
"size_bytes": self.size_bytes,
|
|
48
|
+
"content_hash": self.content_hash,
|
|
49
|
+
"is_text": self.is_text,
|
|
50
|
+
"signals": self.signals,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class ProjectDiscoveryReport:
|
|
56
|
+
"""Comprehensive structured inventory of all discovered workspace assets."""
|
|
57
|
+
root_path: Path
|
|
58
|
+
is_git_repo: bool
|
|
59
|
+
manifests: list[DiscoveredFile] = field(default_factory=list)
|
|
60
|
+
configs: list[DiscoveredFile] = field(default_factory=list)
|
|
61
|
+
adrs: list[DiscoveredFile] = field(default_factory=list)
|
|
62
|
+
docs: list[DiscoveredFile] = field(default_factory=list)
|
|
63
|
+
schemas: list[DiscoveredFile] = field(default_factory=list)
|
|
64
|
+
sources: list[DiscoveredFile] = field(default_factory=list)
|
|
65
|
+
tests: list[DiscoveredFile] = field(default_factory=list)
|
|
66
|
+
unknown_text: list[DiscoveredFile] = field(default_factory=list)
|
|
67
|
+
all_discovered: list[DiscoveredFile] = field(default_factory=list)
|
|
68
|
+
git_head: Optional[str] = None
|
|
69
|
+
git_tags: list[str] = field(default_factory=list)
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def all_files(self) -> list[DiscoveredFile]:
|
|
73
|
+
"""All indexed files relevant for extraction."""
|
|
74
|
+
return self.all_discovered
|
|
75
|
+
|
|
76
|
+
def to_inventory_dict(self) -> dict:
|
|
77
|
+
return {
|
|
78
|
+
"root_path": str(self.root_path),
|
|
79
|
+
"is_git_repo": self.is_git_repo,
|
|
80
|
+
"git_head": self.git_head,
|
|
81
|
+
"total_files_discovered": len(self.all_discovered),
|
|
82
|
+
"counts": {
|
|
83
|
+
"manifests": len(self.manifests),
|
|
84
|
+
"configs": len(self.configs),
|
|
85
|
+
"adrs": len(self.adrs),
|
|
86
|
+
"docs": len(self.docs),
|
|
87
|
+
"schemas": len(self.schemas),
|
|
88
|
+
"sources": len(self.sources),
|
|
89
|
+
"tests": len(self.tests),
|
|
90
|
+
"unknown_text": len(self.unknown_text),
|
|
91
|
+
},
|
|
92
|
+
"files": [f.to_dict() for f in self.all_discovered],
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def compute_file_sha256(path: Path) -> str:
|
|
97
|
+
"""Compute SHA-256 hash of a file."""
|
|
98
|
+
h = hashlib.sha256()
|
|
99
|
+
try:
|
|
100
|
+
with open(path, "rb") as f:
|
|
101
|
+
while chunk := f.read(65536):
|
|
102
|
+
h.update(chunk)
|
|
103
|
+
return h.hexdigest()
|
|
104
|
+
except Exception:
|
|
105
|
+
return ""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def parse_gitignore(root: Path) -> list[str]:
|
|
109
|
+
"""Load gitignore and git info exclude patterns."""
|
|
110
|
+
patterns: list[str] = []
|
|
111
|
+
candidates = [root / ".gitignore", root / ".git" / "info" / "exclude"]
|
|
112
|
+
for gitignore_path in candidates:
|
|
113
|
+
if gitignore_path.exists():
|
|
114
|
+
try:
|
|
115
|
+
with open(gitignore_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
116
|
+
for line in f:
|
|
117
|
+
line = line.strip()
|
|
118
|
+
if line and not line.startswith("#"):
|
|
119
|
+
patterns.append(line.rstrip("/"))
|
|
120
|
+
except Exception:
|
|
121
|
+
pass
|
|
122
|
+
return patterns
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def is_ignored(rel_path: str, patterns: list[str]) -> bool:
|
|
126
|
+
"""Basic gitignore matching for directory segments and file names."""
|
|
127
|
+
norm = rel_path.replace("\\", "/")
|
|
128
|
+
parts = norm.split("/")
|
|
129
|
+
for pat in patterns:
|
|
130
|
+
clean_pat = pat.strip("/")
|
|
131
|
+
if not clean_pat:
|
|
132
|
+
continue
|
|
133
|
+
# Direct part match
|
|
134
|
+
if clean_pat in parts:
|
|
135
|
+
return True
|
|
136
|
+
if clean_pat.startswith("*") and norm.endswith(clean_pat[1:]):
|
|
137
|
+
return True
|
|
138
|
+
if norm == clean_pat or norm.startswith(clean_pat + "/"):
|
|
139
|
+
return True
|
|
140
|
+
return False
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _map_role_to_legacy_file_type(role: FileRole, rel_path: str) -> str:
|
|
144
|
+
"""Map FileRole to legacy file_type for backwards compatibility."""
|
|
145
|
+
if role == FileRole.PROJECT_DESCRIPTOR or role == FileRole.BUILD_CONFIG:
|
|
146
|
+
return "manifest"
|
|
147
|
+
if role == FileRole.STRUCTURED_CONFIG:
|
|
148
|
+
return "config"
|
|
149
|
+
if role == FileRole.DOCUMENTATION:
|
|
150
|
+
norm = rel_path.replace("\\", "/").lower()
|
|
151
|
+
if "adr" in norm or "/decisions/" in norm:
|
|
152
|
+
return "adr"
|
|
153
|
+
return "documentation"
|
|
154
|
+
if role in (FileRole.SCHEMA, FileRole.MIGRATION):
|
|
155
|
+
return "schema"
|
|
156
|
+
if role == FileRole.SOURCE_CODE:
|
|
157
|
+
return "source"
|
|
158
|
+
if role == FileRole.TEST:
|
|
159
|
+
return "test"
|
|
160
|
+
return "unknown"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _determine_authority_for_file(role: FileRole, rel_path: str, format_name: str) -> SourceAuthority:
|
|
164
|
+
"""Determine initial source authority based on file role and location."""
|
|
165
|
+
norm = rel_path.replace("\\", "/").lower()
|
|
166
|
+
name = Path(rel_path).name.lower()
|
|
167
|
+
|
|
168
|
+
if role == FileRole.DEPLOYMENT:
|
|
169
|
+
return SourceAuthority.DEPLOYMENT_CONFIG
|
|
170
|
+
if role == FileRole.BUILD_CONFIG or role == FileRole.PROJECT_DESCRIPTOR:
|
|
171
|
+
return SourceAuthority.BUILD_CONFIG
|
|
172
|
+
if role == FileRole.SCHEMA or role == FileRole.MIGRATION:
|
|
173
|
+
return SourceAuthority.SCHEMA_MIGRATION
|
|
174
|
+
if role == FileRole.STRUCTURED_CONFIG:
|
|
175
|
+
if any(prod in name for prod in ("prod", "production", "release")):
|
|
176
|
+
return SourceAuthority.PROD_CONFIG
|
|
177
|
+
if any(dev in name for dev in ("dev", "local", "docker-compose")):
|
|
178
|
+
return SourceAuthority.DEV_CONFIG
|
|
179
|
+
if "example" in name or "sample" in name or "template" in name:
|
|
180
|
+
return SourceAuthority.EXAMPLE_CONFIG
|
|
181
|
+
return SourceAuthority.PROD_CONFIG
|
|
182
|
+
if role == FileRole.DOCUMENTATION:
|
|
183
|
+
if "adr" in norm or "/decisions/" in norm:
|
|
184
|
+
return SourceAuthority.ADR_DECISION
|
|
185
|
+
return SourceAuthority.DOCS_TECHNICAL
|
|
186
|
+
if role == FileRole.SOURCE_CODE:
|
|
187
|
+
return SourceAuthority.SOURCE_IMPLEMENTATION
|
|
188
|
+
return SourceAuthority.INFERRED_HEURISTIC
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def discover_project(root: Path, include_suppressed: bool = False) -> ProjectDiscoveryReport:
|
|
192
|
+
"""Universally scan codebase to discover and classify all artifacts."""
|
|
193
|
+
root = root.resolve()
|
|
194
|
+
is_git = (root / ".git").exists()
|
|
195
|
+
gitignore_patterns = parse_gitignore(root)
|
|
196
|
+
|
|
197
|
+
report = ProjectDiscoveryReport(root_path=root, is_git_repo=is_git)
|
|
198
|
+
|
|
199
|
+
if is_git:
|
|
200
|
+
try:
|
|
201
|
+
result = subprocess.run(
|
|
202
|
+
["git", "-C", str(root), "--no-optional-locks", "rev-parse", "HEAD"],
|
|
203
|
+
capture_output=True, text=True, timeout=10, check=False,
|
|
204
|
+
)
|
|
205
|
+
if result.returncode == 0:
|
|
206
|
+
report.git_head = result.stdout.strip()
|
|
207
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
208
|
+
pass
|
|
209
|
+
|
|
210
|
+
# Recursive directory walk
|
|
211
|
+
for current_dir, dirnames, filenames in os.walk(root):
|
|
212
|
+
rel_dir = os.path.relpath(current_dir, root)
|
|
213
|
+
if rel_dir == ".":
|
|
214
|
+
rel_dir = ""
|
|
215
|
+
|
|
216
|
+
# Prune ignored directories in-place
|
|
217
|
+
pruned_dirs = []
|
|
218
|
+
for d in dirnames:
|
|
219
|
+
rel_d = os.path.join(rel_dir, d).replace("\\", "/")
|
|
220
|
+
if is_ignored(rel_d, gitignore_patterns) or d in (".git", ".dandelion"):
|
|
221
|
+
pruned_dirs.append(d)
|
|
222
|
+
for d in pruned_dirs:
|
|
223
|
+
dirnames.remove(d)
|
|
224
|
+
|
|
225
|
+
for fname in filenames:
|
|
226
|
+
# Linked worktrees use a .git *file* pointing outside the source;
|
|
227
|
+
# it is repository metadata, never a project artifact.
|
|
228
|
+
if fname == ".git":
|
|
229
|
+
continue
|
|
230
|
+
rel_f = os.path.join(rel_dir, fname).replace("\\", "/")
|
|
231
|
+
if is_ignored(rel_f, gitignore_patterns):
|
|
232
|
+
continue
|
|
233
|
+
|
|
234
|
+
abs_f = Path(current_dir) / fname
|
|
235
|
+
classification: ClassificationResult = classify_content(rel_f, abs_f)
|
|
236
|
+
|
|
237
|
+
if classification.is_suppressed and not include_suppressed:
|
|
238
|
+
continue
|
|
239
|
+
|
|
240
|
+
size = abs_f.stat().st_size if abs_f.exists() else 0
|
|
241
|
+
file_hash = compute_file_sha256(abs_f)
|
|
242
|
+
authority = _determine_authority_for_file(classification.role, rel_f, classification.detected_format)
|
|
243
|
+
legacy_type = _map_role_to_legacy_file_type(classification.role, rel_f)
|
|
244
|
+
|
|
245
|
+
discovered = DiscoveredFile(
|
|
246
|
+
rel_path=rel_f,
|
|
247
|
+
abs_path=abs_f,
|
|
248
|
+
file_type=legacy_type,
|
|
249
|
+
role=classification.role,
|
|
250
|
+
authority=authority,
|
|
251
|
+
format=classification.detected_format,
|
|
252
|
+
size_bytes=size,
|
|
253
|
+
content_hash=file_hash,
|
|
254
|
+
is_text=classification.is_text,
|
|
255
|
+
signals=classification.signals,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
report.all_discovered.append(discovered)
|
|
259
|
+
|
|
260
|
+
# Categorize into specialized groups
|
|
261
|
+
if classification.role in (FileRole.PROJECT_DESCRIPTOR, FileRole.BUILD_CONFIG):
|
|
262
|
+
report.manifests.append(discovered)
|
|
263
|
+
if classification.role in (FileRole.STRUCTURED_CONFIG, FileRole.DEPLOYMENT):
|
|
264
|
+
report.configs.append(discovered)
|
|
265
|
+
elif classification.role == FileRole.DOCUMENTATION:
|
|
266
|
+
if legacy_type == "adr":
|
|
267
|
+
report.adrs.append(discovered)
|
|
268
|
+
else:
|
|
269
|
+
report.docs.append(discovered)
|
|
270
|
+
elif classification.role in (FileRole.SCHEMA, FileRole.MIGRATION):
|
|
271
|
+
report.schemas.append(discovered)
|
|
272
|
+
elif classification.role == FileRole.SOURCE_CODE:
|
|
273
|
+
report.sources.append(discovered)
|
|
274
|
+
elif classification.role == FileRole.TEST:
|
|
275
|
+
report.tests.append(discovered)
|
|
276
|
+
elif classification.role == FileRole.UNKNOWN_TEXT:
|
|
277
|
+
report.unknown_text.append(discovered)
|
|
278
|
+
|
|
279
|
+
return report
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Dynamic Domain Induction & Importance Hierarchy (BOOTSTRAP-02 Sections 11-13).
|
|
2
|
+
|
|
3
|
+
Derives canonical hierarchical domain partitions from the Component Graph and
|
|
4
|
+
evidence-weighted structural importance.
|
|
5
|
+
CRITICAL INVARIANTS:
|
|
6
|
+
1. No hardcoded industry/application categories (finance, gaming, medicine).
|
|
7
|
+
2. Size != Importance: asset directories do not outrank runtime code.
|
|
8
|
+
3. Every induced domain retains full provenance and confidence explanation.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Any, Optional
|
|
16
|
+
|
|
17
|
+
from dandelion.domains import PartitionDescriptor, PartitionKey
|
|
18
|
+
from dandelion.bootstrap.component_graph import ComponentGraph, ComponentNode
|
|
19
|
+
from dandelion.bootstrap.root_resolver import RootResolutionResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class InducedDomain:
|
|
24
|
+
"""An evidence-derived domain partition."""
|
|
25
|
+
canonical_id: str
|
|
26
|
+
project: str
|
|
27
|
+
domain: str
|
|
28
|
+
component: str
|
|
29
|
+
structural_role: str # ROOT, MAJOR_COMPONENT, SUBSYSTEM, MODULE, LEAF
|
|
30
|
+
importance_score: float # [0.0 - 1.0]
|
|
31
|
+
confidence: float # [0.0 - 1.0]
|
|
32
|
+
evidence: list[str] = field(default_factory=list)
|
|
33
|
+
technologies: list[str] = field(default_factory=list)
|
|
34
|
+
keywords: list[str] = field(default_factory=list)
|
|
35
|
+
|
|
36
|
+
def to_dict(self) -> dict:
|
|
37
|
+
return {
|
|
38
|
+
"canonical_id": self.canonical_id,
|
|
39
|
+
"project": self.project,
|
|
40
|
+
"domain": self.domain,
|
|
41
|
+
"component": self.component,
|
|
42
|
+
"structural_role": self.structural_role,
|
|
43
|
+
"importance_score": round(self.importance_score, 2),
|
|
44
|
+
"confidence": round(self.confidence, 2),
|
|
45
|
+
"evidence": self.evidence,
|
|
46
|
+
"technologies": self.technologies,
|
|
47
|
+
"keywords": self.keywords,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
def to_partition_descriptor(self) -> PartitionDescriptor:
|
|
51
|
+
"""Convert to Dandelion's runtime PartitionDescriptor for C4.2 routing."""
|
|
52
|
+
key = PartitionKey(
|
|
53
|
+
project=self.project,
|
|
54
|
+
domain=self.domain,
|
|
55
|
+
component=self.component,
|
|
56
|
+
)
|
|
57
|
+
title = f"{self.project.capitalize()} - {self.domain.capitalize()} ({self.component})"
|
|
58
|
+
desc = (
|
|
59
|
+
f"Component '{self.component}' in domain '{self.domain}'. "
|
|
60
|
+
f"Role: {self.structural_role}. Technologies: {', '.join(self.technologies) if self.technologies else 'general'}."
|
|
61
|
+
)
|
|
62
|
+
return PartitionDescriptor(
|
|
63
|
+
key=key,
|
|
64
|
+
title=title,
|
|
65
|
+
description=desc,
|
|
66
|
+
service_role=self.domain,
|
|
67
|
+
keywords=self.keywords or [self.project, self.domain, self.component],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _compute_importance(node: ComponentNode) -> tuple[str, float, list[str]]:
|
|
72
|
+
"""Compute structural role and importance score from evidence."""
|
|
73
|
+
score = 0.0
|
|
74
|
+
evidence: list[str] = []
|
|
75
|
+
|
|
76
|
+
if node.is_root:
|
|
77
|
+
return "ROOT", 1.0, ["workspace_root_boundary"]
|
|
78
|
+
|
|
79
|
+
# 1. Independent descriptors / build systems
|
|
80
|
+
if node.descriptors:
|
|
81
|
+
score += 0.35
|
|
82
|
+
evidence.append(f"owns_descriptors:{len(node.descriptors)}")
|
|
83
|
+
|
|
84
|
+
# 2. Source code density (not raw asset bytes!)
|
|
85
|
+
if node.source_files_count > 0:
|
|
86
|
+
score += min(0.30, node.source_files_count * 0.02)
|
|
87
|
+
evidence.append(f"source_files:{node.source_files_count}")
|
|
88
|
+
|
|
89
|
+
# 3. Structural degree in component graph
|
|
90
|
+
if node.in_degree > 0:
|
|
91
|
+
score += min(0.20, node.in_degree * 0.10)
|
|
92
|
+
evidence.append(f"in_degree_references:{node.in_degree}")
|
|
93
|
+
if node.out_degree > 0:
|
|
94
|
+
score += min(0.15, node.out_degree * 0.05)
|
|
95
|
+
|
|
96
|
+
# 4. Role-based weighting
|
|
97
|
+
if node.kind in ("service", "application"):
|
|
98
|
+
score += 0.20
|
|
99
|
+
evidence.append("runtime_system_role")
|
|
100
|
+
elif node.kind == "plugin":
|
|
101
|
+
score += 0.15
|
|
102
|
+
evidence.append("extension_plugin_role")
|
|
103
|
+
elif node.kind == "subsystem":
|
|
104
|
+
score += 0.10
|
|
105
|
+
evidence.append("core_subsystem_role")
|
|
106
|
+
|
|
107
|
+
final_score = min(1.0, score)
|
|
108
|
+
|
|
109
|
+
# Structural role thresholding
|
|
110
|
+
if final_score >= 0.70:
|
|
111
|
+
role = "MAJOR_COMPONENT"
|
|
112
|
+
elif final_score >= 0.40:
|
|
113
|
+
role = "SUBSYSTEM"
|
|
114
|
+
elif final_score >= 0.20:
|
|
115
|
+
role = "MODULE"
|
|
116
|
+
else:
|
|
117
|
+
role = "LEAF"
|
|
118
|
+
|
|
119
|
+
return role, final_score, evidence
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def induce_domains_from_graph(
|
|
123
|
+
graph: ComponentGraph,
|
|
124
|
+
root_res: RootResolutionResult,
|
|
125
|
+
) -> list[InducedDomain]:
|
|
126
|
+
"""Induce dynamic domain topology without any industry-specific catalog."""
|
|
127
|
+
pname = root_res.project_name
|
|
128
|
+
induced: list[InducedDomain] = []
|
|
129
|
+
|
|
130
|
+
# 1. Architecture & Global Overview Domain
|
|
131
|
+
induced.append(InducedDomain(
|
|
132
|
+
canonical_id=f"{pname}/architecture/overview",
|
|
133
|
+
project=pname,
|
|
134
|
+
domain="architecture",
|
|
135
|
+
component="overview",
|
|
136
|
+
structural_role="ROOT",
|
|
137
|
+
importance_score=1.0,
|
|
138
|
+
confidence=1.0,
|
|
139
|
+
evidence=["root_project_architecture", "global_decisions"],
|
|
140
|
+
technologies=graph.nodes.get(graph.root_id, ComponentNode(id="", name="", kind="", rel_path="")).technologies,
|
|
141
|
+
keywords=[pname, "architecture", "overview", "system", "design"],
|
|
142
|
+
))
|
|
143
|
+
|
|
144
|
+
# 2. Induce Domains from Nodes
|
|
145
|
+
for cid, node in graph.nodes.items():
|
|
146
|
+
if node.is_root:
|
|
147
|
+
continue
|
|
148
|
+
|
|
149
|
+
role, importance, evidence = _compute_importance(node)
|
|
150
|
+
|
|
151
|
+
# Formulate canonical 3-tier key: project / domain / component
|
|
152
|
+
parts = node.rel_path.split("/")
|
|
153
|
+
if len(parts) == 1:
|
|
154
|
+
domain_name = "core"
|
|
155
|
+
comp_name = parts[0]
|
|
156
|
+
else:
|
|
157
|
+
domain_name = parts[0]
|
|
158
|
+
comp_name = parts[1]
|
|
159
|
+
|
|
160
|
+
canonical = f"{pname}/{domain_name}/{comp_name}"
|
|
161
|
+
|
|
162
|
+
# Keywords for retrieval routing
|
|
163
|
+
kw = {pname, domain_name, comp_name}
|
|
164
|
+
kw.update(node.name.lower().split("_"))
|
|
165
|
+
kw.update(t.lower() for t in node.technologies)
|
|
166
|
+
|
|
167
|
+
induced.append(InducedDomain(
|
|
168
|
+
canonical_id=canonical,
|
|
169
|
+
project=pname,
|
|
170
|
+
domain=domain_name,
|
|
171
|
+
component=comp_name,
|
|
172
|
+
structural_role=role,
|
|
173
|
+
importance_score=importance,
|
|
174
|
+
confidence=0.90 if node.descriptors else 0.80,
|
|
175
|
+
evidence=evidence,
|
|
176
|
+
technologies=node.technologies,
|
|
177
|
+
keywords=sorted(list(kw)),
|
|
178
|
+
))
|
|
179
|
+
|
|
180
|
+
return induced
|