Skip to content

Commit 05ae6ff

Browse files
authored
Merge pull request #27 from BruinGrowly/claude/reca-implementation-011CV1d52gvgXZqoYNqR66kt
Guardian self-healing: Auto-format entire codebase with black
2 parents ee3996c + 19c77a7 commit 05ae6ff

36 files changed

Lines changed: 1305 additions & 1564 deletions

guardian/advanced/gap_analyzer.py

Lines changed: 94 additions & 105 deletions
Large diffs are not rendered by default.

guardian/analyzers/geopolitical.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def __init__(self, vocab_manager: VocabularyManager):
3030
self.entity_database = {}
3131
self.analysis_history = []
3232

33-
def analyze_entity_posture(self, entity_name: str, entity_type: str,
34-
recent_actions: str, historical_context: str = "") -> Dict:
33+
def analyze_entity_posture(
34+
self, entity_name: str, entity_type: str, recent_actions: str, historical_context: str = ""
35+
) -> Dict:
3536
"""
3637
Analyze geopolitical entity posture
3738
@@ -48,13 +49,12 @@ def analyze_entity_posture(self, entity_name: str, entity_type: str,
4849
recent_coords = self.vocab.analyze_concept(recent_actions)
4950

5051
# Analyze historical context if provided
51-
historical_coords = (self.vocab.analyze_concept(historical_context)
52-
if historical_context else Coordinates(0, 0, 0, 0))
52+
historical_coords = (
53+
self.vocab.analyze_concept(historical_context) if historical_context else Coordinates(0, 0, 0, 0)
54+
)
5355

5456
# Combine analyses (recent weighted higher)
55-
combined_coords = self._calculate_weighted_average(
56-
[recent_coords, historical_coords], [0.7, 0.3]
57-
)
57+
combined_coords = self._calculate_weighted_average([recent_coords, historical_coords], [0.7, 0.3])
5858

5959
result = self._determine_posture_type(combined_coords, entity_name, entity_type)
6060

@@ -64,8 +64,7 @@ def analyze_entity_posture(self, entity_name: str, entity_type: str,
6464

6565
return result
6666

67-
def _calculate_weighted_average(self, coords_list: List[Coordinates],
68-
weights: List[float]) -> Coordinates:
67+
def _calculate_weighted_average(self, coords_list: List[Coordinates], weights: List[float]) -> Coordinates:
6968
"""Calculate weighted average coordinates"""
7069
if not coords_list:
7170
return Coordinates(0, 0, 0, 0)
@@ -86,11 +85,10 @@ def _calculate_weighted_average(self, coords_list: List[Coordinates],
8685
love=weighted_love / total_weight,
8786
justice=weighted_justice / total_weight,
8887
power=weighted_power / total_weight,
89-
wisdom=weighted_wisdom / total_weight
88+
wisdom=weighted_wisdom / total_weight,
9089
)
9190

92-
def _determine_posture_type(self, coords: Coordinates, entity_name: str,
93-
entity_type: str) -> Dict:
91+
def _determine_posture_type(self, coords: Coordinates, entity_name: str, entity_type: str) -> Dict:
9492
"""Determine geopolitical posture type based on coordinates"""
9593
distance = self.vocab.get_distance_from_anchor(coords)
9694
clarity = self.vocab.get_semantic_clarity(coords)
@@ -151,7 +149,7 @@ def _determine_posture_type(self, coords: Coordinates, entity_name: str,
151149
"stability_indicator": 1.0 / distance if distance > 0 else 0,
152150
"cooperation_level": coords.love + coords.justice if distance < 2.0 else 0,
153151
"aggression_level": coords.power if distance > 2.0 else 0,
154-
"wisdom_level": coords.wisdom if distance < 2.0 else 0
152+
"wisdom_level": coords.wisdom if distance < 2.0 else 0,
155153
}
156154

157155
def analyze_global_dynamics(self, entity_results: List[Dict]) -> Dict:
@@ -183,11 +181,9 @@ def analyze_global_dynamics(self, entity_results: List[Dict]) -> Dict:
183181
avg_stability = total_stability / len(entity_results)
184182

185183
# Determine global trend
186-
global_stability_trend = ("improving" if avg_stability > 0.7 else
187-
"stable" if avg_stability > 0.4 else "volatile")
184+
global_stability_trend = "improving" if avg_stability > 0.7 else "stable" if avg_stability > 0.4 else "volatile"
188185

189-
logger.info(f"Global dynamics analysis: {len(entity_results)} entities, "
190-
f"trend={global_stability_trend}")
186+
logger.info(f"Global dynamics analysis: {len(entity_results)} entities, " f"trend={global_stability_trend}")
191187

192188
return {
193189
"status": "Analysis Complete",
@@ -197,8 +193,8 @@ def analyze_global_dynamics(self, entity_results: List[Dict]) -> Dict:
197193
"global_trend": global_stability_trend,
198194
"total_cooperation": total_cooperation / len(entity_results),
199195
"total_aggression": total_aggression / len(entity_results),
200-
"total_wisdom": total_wisdom / len(entity_results)
196+
"total_wisdom": total_wisdom / len(entity_results),
201197
},
202198
"posture_distribution": posture_distribution,
203-
"global_stability_indicator": avg_stability
199+
"global_stability_indicator": avg_stability,
204200
}

guardian/analyzers/ice.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ def __init__(self, vocab_manager: VocabularyManager):
2828
"""
2929
self.vocab = vocab_manager
3030

31-
def analyze_comprehensive_ice(self, concept: str,
32-
intent_words: List[str],
33-
context_words: List[str],
34-
execution_words: List[str]) -> Dict:
31+
def analyze_comprehensive_ice(
32+
self, concept: str, intent_words: List[str], context_words: List[str], execution_words: List[str]
33+
) -> Dict:
3534
"""
3635
Comprehensive ICE analysis
3736
@@ -45,9 +44,9 @@ def analyze_comprehensive_ice(self, concept: str,
4544
Dictionary with ICE analysis results
4645
"""
4746
# Analyze individual components
48-
intent_coords = self.vocab.analyze_concept(' '.join(intent_words))
49-
context_coords = self.vocab.analyze_concept(' '.join(context_words))
50-
execution_coords = self.vocab.analyze_concept(' '.join(execution_words))
47+
intent_coords = self.vocab.analyze_concept(" ".join(intent_words))
48+
context_coords = self.vocab.analyze_concept(" ".join(context_words))
49+
execution_coords = self.vocab.analyze_concept(" ".join(execution_words))
5150

5251
# Analyze overall concept
5352
all_coords = [intent_coords, context_coords, execution_coords]
@@ -69,42 +68,44 @@ def analyze_comprehensive_ice(self, concept: str,
6968
# Calculate benevolence score
7069
benevolence_score = (execution_coords.love + context_coords.love) / 2
7170

72-
logger.debug(f"ICE analysis for '{concept}': balance={ice_balance:.3f}, "
73-
f"coherence={ice_coherence:.3f}")
71+
logger.debug(f"ICE analysis for '{concept}': balance={ice_balance:.3f}, " f"coherence={ice_coherence:.3f}")
7472

7573
return {
7674
"concept": concept,
7775
"ice_components": {
7876
"intent": {
7977
"coordinates": intent_coords,
8078
"distance_from_anchor": intent_distance,
81-
"clarity": self.vocab.get_semantic_clarity(intent_coords)
79+
"clarity": self.vocab.get_semantic_clarity(intent_coords),
8280
},
8381
"context": {
8482
"coordinates": context_coords,
8583
"distance_from_anchor": context_distance,
86-
"clarity": self.vocab.get_semantic_clarity(context_coords)
84+
"clarity": self.vocab.get_semantic_clarity(context_coords),
8785
},
8886
"execution": {
8987
"coordinates": execution_coords,
9088
"distance_from_anchor": execution_distance,
91-
"clarity": self.vocab.get_semantic_clarity(execution_coords)
89+
"clarity": self.vocab.get_semantic_clarity(execution_coords),
9290
},
9391
"overall": {
9492
"coordinates": overall_coords,
9593
"combined_distance": (intent_distance + context_distance + execution_distance) / 3,
96-
"combined_clarity": (self.vocab.get_semantic_clarity(intent_coords) +
97-
self.vocab.get_semantic_clarity(context_coords) +
98-
self.vocab.get_semantic_clarity(execution_coords)) / 3
99-
}
94+
"combined_clarity": (
95+
self.vocab.get_semantic_clarity(intent_coords)
96+
+ self.vocab.get_semantic_clarity(context_coords)
97+
+ self.vocab.get_semantic_clarity(execution_coords)
98+
)
99+
/ 3,
100+
},
100101
},
101102
"ice_metrics": {
102103
"ice_balance": ice_balance,
103104
"ice_coherence": ice_coherence,
104-
"benevolence_score": benevolence_score
105+
"benevolence_score": benevolence_score,
105106
},
106107
"ice_harmony_level": self._determine_ice_harmony_level(ice_balance),
107-
"is_ice_aligned": ice_balance > 0.8
108+
"is_ice_aligned": ice_balance > 0.8,
108109
}
109110

110111
def _determine_ice_harmony_level(self, ice_balance: float) -> str:
@@ -128,8 +129,7 @@ def _determine_ice_harmony_level(self, ice_balance: float) -> str:
128129
else:
129130
return "POOR_ICE_BALANCE"
130131

131-
def _calculate_weighted_average(self, coords_list: List[Coordinates],
132-
weights: List[float]) -> Coordinates:
132+
def _calculate_weighted_average(self, coords_list: List[Coordinates], weights: List[float]) -> Coordinates:
133133
"""
134134
Calculate weighted average coordinates
135135
@@ -160,5 +160,5 @@ def _calculate_weighted_average(self, coords_list: List[Coordinates],
160160
love=weighted_love / total_weight,
161161
justice=weighted_justice / total_weight,
162162
power=weighted_power / total_weight,
163-
wisdom=weighted_wisdom / total_weight
163+
wisdom=weighted_wisdom / total_weight,
164164
)

guardian/analyzers/inference.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def infer_unknown_meaning(self, unknown_word: str, context_words: List[str]) ->
4848
coords_list = [self.vocab.analyze_concept(word) for word in context_words]
4949

5050
# Filter out zero coordinates
51-
coords_list = [c for c in coords_list
52-
if c.love + c.justice + c.power + c.wisdom > 0]
51+
coords_list = [c for c in coords_list if c.love + c.justice + c.power + c.wisdom > 0]
5352

5453
if not coords_list:
5554
logger.warning(f"No valid coordinates in context for '{unknown_word}'")
@@ -62,15 +61,15 @@ def infer_unknown_meaning(self, unknown_word: str, context_words: List[str]) ->
6261
centroid_wisdom = sum(c.wisdom for c in coords_list) / len(coords_list)
6362

6463
# Find closest concept to centroid
65-
min_distance = float('inf')
64+
min_distance = float("inf")
6665
closest_concept_index = 0
6766

6867
for i, coords in enumerate(coords_list):
6968
distance = math.sqrt(
70-
(coords.love - centroid_love) ** 2 +
71-
(coords.justice - centroid_justice) ** 2 +
72-
(coords.power - centroid_power) ** 2 +
73-
(coords.wisdom - centroid_wisdom) ** 2
69+
(coords.love - centroid_love) ** 2
70+
+ (coords.justice - centroid_justice) ** 2
71+
+ (coords.power - centroid_power) ** 2
72+
+ (coords.wisdom - centroid_wisdom) ** 2
7473
)
7574

7675
if distance < min_distance:
@@ -82,16 +81,18 @@ def infer_unknown_meaning(self, unknown_word: str, context_words: List[str]) ->
8281
# Calculate confidence (inverse of distance, clamped to [0, 1])
8382
confidence = max(0.0, min(1.0, 1.0 - min_distance))
8483

85-
logger.info(f"Inferred meaning for '{unknown_word}' from {len(context_words)} "
86-
f"context words, confidence={confidence:.3f}")
84+
logger.info(
85+
f"Inferred meaning for '{unknown_word}' from {len(context_words)} "
86+
f"context words, confidence={confidence:.3f}"
87+
)
8788

8889
return SemanticResult(
8990
coordinates=closest_concept_coords,
9091
distance_from_anchor=self.vocab.get_distance_from_anchor(closest_concept_coords),
9192
semantic_clarity=self.vocab.get_semantic_clarity(closest_concept_coords),
9293
concept_count=len(context_words),
9394
confidence=confidence,
94-
closest_concept=context_words[closest_concept_index]
95+
closest_concept=context_words[closest_concept_index],
9596
)
9697

9798
def _empty_result(self) -> SemanticResult:
@@ -101,5 +102,5 @@ def _empty_result(self) -> SemanticResult:
101102
distance_from_anchor=2.0,
102103
semantic_clarity=0.0,
103104
concept_count=0,
104-
confidence=0.0
105+
confidence=0.0,
105106
)

guardian/analyzers/phi.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def calculate_phi_optimization(self, coords_list: List[Coordinates]) -> Dict:
5151
centroid_power = sum(c.power for c in coords_list) / len(coords_list)
5252
centroid_wisdom = sum(c.wisdom for c in coords_list) / len(coords_list)
5353

54-
centroid = Coordinates(centroid_love, centroid_justice,
55-
centroid_power, centroid_wisdom)
54+
centroid = Coordinates(centroid_love, centroid_justice, centroid_power, centroid_wisdom)
5655

5756
# Calculate phi-weighted distances
5857
phi_distances = []
@@ -70,8 +69,7 @@ def calculate_phi_optimization(self, coords_list: List[Coordinates]) -> Dict:
7069
phi_mean = sum(phi_distances) / len(phi_distances)
7170
phi_variance = sum((d - phi_mean) ** 2 for d in phi_distances) / len(phi_distances)
7271

73-
logger.debug(f"Phi optimization: perfection={phi_perfection:.2f}%, "
74-
f"optimization={phi_optimization:.3f}")
72+
logger.debug(f"Phi optimization: perfection={phi_perfection:.2f}%, " f"optimization={phi_optimization:.3f}")
7573

7674
return {
7775
"centroid": centroid,
@@ -81,7 +79,7 @@ def calculate_phi_optimization(self, coords_list: List[Coordinates]) -> Dict:
8179
"phi_variance": phi_variance,
8280
"phi_mean": phi_mean,
8381
"min_phi_distance": min_phi_distance,
84-
"max_phi_distance": max_phi_distance
82+
"max_phi_distance": max_phi_distance,
8583
}
8684

8785
def get_phi_score(self, coords: Coordinates) -> float:
@@ -108,5 +106,5 @@ def _empty_result(self) -> Dict:
108106
"phi_variance": 0.0,
109107
"phi_mean": 0.0,
110108
"min_phi_distance": 0.0,
111-
"max_phi_distance": 0.0
109+
"max_phi_distance": 0.0,
112110
}

guardian/analyzers/semantic.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ def _calculate_cluster_analysis(self, coords_list: List[Coordinates]) -> Semanti
6969
distances = []
7070
for coords in coords_list:
7171
distance = math.sqrt(
72-
(coords.love - centroid_love) ** 2 +
73-
(coords.justice - centroid_justice) ** 2 +
74-
(coords.power - centroid_power) ** 2 +
75-
(coords.wisdom - centroid_wisdom) ** 2
72+
(coords.love - centroid_love) ** 2
73+
+ (coords.justice - centroid_justice) ** 2
74+
+ (coords.power - centroid_power) ** 2
75+
+ (coords.wisdom - centroid_wisdom) ** 2
7676
)
7777
distances.append(distance)
7878

7979
# Calculate harmonic cohesion
8080
avg_distance = sum(distances) / len(distances)
8181
harmonic_cohesion = max(0.0, 1.0 - avg_distance)
8282

83-
logger.debug(f"Cluster analysis: {len(coords_list)} concepts, "
84-
f"cohesion={harmonic_cohesion:.3f}")
83+
logger.debug(f"Cluster analysis: {len(coords_list)} concepts, " f"cohesion={harmonic_cohesion:.3f}")
8584

8685
return SemanticResult(
8786
coordinates=coords_list[0] if coords_list else Coordinates(0, 0, 0, 0),
@@ -90,7 +89,7 @@ def _calculate_cluster_analysis(self, coords_list: List[Coordinates]) -> Semanti
9089
concept_count=len(coords_list),
9190
confidence=harmonic_cohesion,
9291
distances=distances,
93-
harmonic_cohesion=harmonic_cohesion
92+
harmonic_cohesion=harmonic_cohesion,
9493
)
9594

9695
def _empty_result(self) -> SemanticResult:
@@ -100,5 +99,5 @@ def _empty_result(self) -> SemanticResult:
10099
distance_from_anchor=2.0,
101100
semantic_clarity=0.0,
102101
concept_count=0,
103-
confidence=0.0
102+
confidence=0.0,
104103
)

guardian/analyzers/unified.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ def calculate_unified_score(self, concepts: List[str]) -> Dict:
6363
delta = 0.05 # Resonance index weight
6464
epsilon = 0.05 # Phi optimization weight
6565

66-
unified_score = (alpha * harmony_score +
67-
beta * geologic_score +
68-
gamma * phi_score +
69-
delta * epsilon)
66+
unified_score = alpha * harmony_score + beta * geologic_score + gamma * phi_score + delta * epsilon
7067

7168
# Determine level and interpretation
7269
level, interpretation = self._get_level_and_interpretation(unified_score)
@@ -82,8 +79,8 @@ def calculate_unified_score(self, concepts: List[str]) -> Dict:
8279
"divine_distance": divine_distance,
8380
"harmonic_cohesion": harmony_score,
8481
"geologic_precision": geologic_score,
85-
"phi_optimization": phi_score
86-
}
82+
"phi_optimization": phi_score,
83+
},
8784
}
8885

8986
def _get_level_and_interpretation(self, score: float) -> tuple:
@@ -127,6 +124,6 @@ def _empty_result(self) -> Dict:
127124
"divine_distance": 2.0,
128125
"harmonic_cohesion": 0.0,
129126
"geologic_precision": 0.0,
130-
"phi_optimization": 0.0
131-
}
127+
"phi_optimization": 0.0,
128+
},
132129
}

guardian/cli/__init__.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@
1010
print_gap_analysis,
1111
print_creator_profile,
1212
print_decrypt_report,
13-
ProgressTracker
13+
ProgressTracker,
1414
)
1515

16-
from guardian.cli.html_reports import (
17-
HTMLReportGenerator,
18-
is_html_available
19-
)
16+
from guardian.cli.html_reports import HTMLReportGenerator, is_html_available
2017

2118
__all__ = [
22-
'print_header',
23-
'print_ljpw_table',
24-
'print_threat_results',
25-
'print_gap_analysis',
26-
'print_creator_profile',
27-
'print_decrypt_report',
28-
'ProgressTracker',
29-
'HTMLReportGenerator',
30-
'is_html_available'
19+
"print_header",
20+
"print_ljpw_table",
21+
"print_threat_results",
22+
"print_gap_analysis",
23+
"print_creator_profile",
24+
"print_decrypt_report",
25+
"ProgressTracker",
26+
"HTMLReportGenerator",
27+
"is_html_available",
3128
]

0 commit comments

Comments
 (0)