Skip to content

Commit 1f0b8ab

Browse files
committed
Merge pull request 'Fix #1: remove 24 dead_code suppressions (wire or delete)' (#20) from task/2895-impl into main
2 parents aad1d94 + 07674cc commit 1f0b8ab

22 files changed

Lines changed: 129 additions & 146 deletions

File tree

.cachebro/cache.db

4 KB
Binary file not shown.

.cachebro/cache.db-shm

32 KB
Binary file not shown.

.cachebro/cache.db-wal

56.4 KB
Binary file not shown.

crates/terraphim_agent_registry/src/knowledge_graph.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use terraphim_rolegraph::RoleGraph;
1313
use crate::{AgentMetadata, RegistryResult};
1414

1515
/// Knowledge graph-based agent discovery and matching
16-
#[allow(dead_code)]
1716
pub struct KnowledgeGraphIntegration {
1817
/// Role graph for role-based agent specialization
1918
role_graph: Arc<RoleGraph>,
@@ -375,6 +374,15 @@ impl KnowledgeGraphIntegration {
375374

376375
/// Extract concepts from text using automata
377376
async fn extract_concepts_from_text(&self, text: &str) -> RegistryResult<Vec<String>> {
377+
// Honour the configured context window: only the leading portion of the
378+
// text (up to `context_window` characters) is scanned for concepts.
379+
let scan_end = text
380+
.char_indices()
381+
.nth(self.automata_config.context_window)
382+
.map(|(idx, _)| idx)
383+
.unwrap_or(text.len());
384+
let text = &text[..scan_end];
385+
378386
// Simple concept extraction - split text into words and filter
379387
let mut concepts = HashSet::new();
380388

@@ -778,6 +786,19 @@ impl KnowledgeGraphIntegration {
778786
));
779787
}
780788

789+
// Advise when the best available match falls below the configured
790+
// similarity thresholds for role or capability compatibility.
791+
if let Some(best) = matches.first()
792+
&& (best.score_breakdown.role_score < self.similarity_thresholds.role_similarity
793+
|| best.score_breakdown.capability_score
794+
< self.similarity_thresholds.capability_similarity)
795+
{
796+
suggestions.push(
797+
"Best match falls below configured similarity thresholds; consider broadening the query"
798+
.to_string(),
799+
);
800+
}
801+
781802
suggestions
782803
}
783804

crates/terraphim_agent_registry/src/matching.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ pub trait KnowledgeGraphAgentMatcher: Send + Sync {
193193
}
194194

195195
/// Knowledge graph-based agent matcher implementation
196-
#[allow(dead_code)]
197196
pub struct TerraphimKnowledgeGraphMatcher {
198197
/// Knowledge graph automata
199198
automata: Arc<Automata>,
@@ -300,6 +299,23 @@ impl TerraphimKnowledgeGraphMatcher {
300299
return Ok(0.0);
301300
}
302301

302+
// Consult the performance cache when caching is enabled. The key is
303+
// built from the (order-independent) concept sets so identical analyses
304+
// are served from memory.
305+
let cache_key = if self.config.enable_caching {
306+
let mut task_sorted = task_concepts.to_vec();
307+
task_sorted.sort();
308+
let mut agent_sorted = agent_concepts.to_vec();
309+
agent_sorted.sort();
310+
let key = format!("{}|{}", task_sorted.join(","), agent_sorted.join(","));
311+
if let Some(cached) = self.cache.read().await.get(&key) {
312+
return Ok(*cached);
313+
}
314+
Some(key)
315+
} else {
316+
None
317+
};
318+
303319
let mut total_connectivity = 0.0;
304320
let mut connection_count = 0;
305321

@@ -334,6 +350,11 @@ impl TerraphimKnowledgeGraphMatcher {
334350
connectivity_score, total_connectivity as u32, connection_count
335351
);
336352

353+
// Store the result for subsequent identical analyses.
354+
if let Some(key) = cache_key {
355+
self.cache.write().await.insert(key, connectivity_score);
356+
}
357+
337358
Ok(connectivity_score)
338359
}
339360

@@ -606,10 +627,25 @@ impl KnowledgeGraphAgentMatcher for TerraphimKnowledgeGraphMatcher {
606627
]
607628
.concat();
608629

609-
let connectivity_score = self
630+
let mut connectivity_score = self
610631
.analyze_connectivity(&task_concepts, &agent_concepts)
611632
.await?;
612633

634+
// If a dedicated role graph exists for the agent's primary role,
635+
// use it to corroborate connectivity. This can only strengthen a
636+
// match (the score is never reduced below the automata result).
637+
if let Some(role_graph) = self.role_graphs.get(&agent.primary_role.role_id) {
638+
let terms = task_concepts
639+
.iter()
640+
.chain(agent_concepts.iter())
641+
.cloned()
642+
.collect::<Vec<_>>()
643+
.join(" ");
644+
if !terms.trim().is_empty() && role_graph.is_all_terms_connected_by_path(&terms) {
645+
connectivity_score = connectivity_score.max(1.0);
646+
}
647+
}
648+
613649
// Calculate overall match score
614650
let match_score = capability_score * self.config.capability_weight
615651
+ domain_score * self.config.domain_weight

crates/terraphim_goal_alignment/src/alignment.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub struct KnowledgeGraphGoalAligner {
2424
goal_hierarchy: Arc<RwLock<GoalHierarchy>>,
2525
/// Knowledge graph analyzer
2626
kg_analyzer: Arc<KnowledgeGraphGoalAnalyzer>,
27-
/// Agent registry for agent-goal assignments
28-
#[allow(dead_code)]
29-
agent_registry: Arc<dyn AgentRegistry>,
30-
/// Role graph for role-based operations
31-
#[allow(dead_code)]
32-
role_graph: Arc<RoleGraph>,
27+
/// Agent registry for agent-goal assignments. Retained as a collaborator
28+
/// for assignment operations; not yet dereferenced by current methods.
29+
_agent_registry: Arc<dyn AgentRegistry>,
30+
/// Role graph for role-based operations. Retained as a collaborator for
31+
/// role-based operations; not yet dereferenced by current methods.
32+
_role_graph: Arc<RoleGraph>,
3333
/// Alignment configuration
3434
config: AlignmentConfig,
3535
/// Alignment statistics
@@ -219,8 +219,8 @@ impl KnowledgeGraphGoalAligner {
219219
Self {
220220
goal_hierarchy: Arc::new(RwLock::new(GoalHierarchy::new())),
221221
kg_analyzer,
222-
agent_registry,
223-
role_graph,
222+
_agent_registry: agent_registry,
223+
_role_graph: role_graph,
224224
config,
225225
statistics: Arc::new(RwLock::new(AlignmentStatistics::default())),
226226
}

crates/terraphim_goal_alignment/src/knowledge_graph.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ use crate::{Goal, GoalAlignmentResult, GoalId};
1616
/// Knowledge graph-based goal analysis and alignment
1717
pub struct KnowledgeGraphGoalAnalyzer {
1818
/// Role graph for role-based goal propagation
19-
#[allow(dead_code)]
2019
role_graph: Arc<RoleGraph>,
2120
/// Configuration for automata-based analysis
22-
#[allow(dead_code)]
2321
automata_config: AutomataConfig,
2422
/// Cached analysis results for performance
2523
analysis_cache: Arc<tokio::sync::RwLock<HashMap<String, AnalysisResult>>>,
@@ -410,6 +408,15 @@ impl KnowledgeGraphGoalAnalyzer {
410408
goal.knowledge_context.keywords.join(" ")
411409
);
412410

411+
// Honour the configured context window: only the leading portion of the
412+
// text (up to `context_window` characters) is scanned for concepts.
413+
let scan_end = text
414+
.char_indices()
415+
.nth(self.automata_config.context_window)
416+
.map(|(idx, _)| idx)
417+
.unwrap_or(text.len());
418+
let text = &text[..scan_end];
419+
413420
// Temporary fallback: simple word extraction until we integrate thesaurus
414421
let mut concepts = HashSet::new();
415422
let words: Vec<&str> = text.split_whitespace().collect();
@@ -583,14 +590,12 @@ impl KnowledgeGraphGoalAnalyzer {
583590
});
584591
}
585592

586-
// TODO: Re-implement connectivity check with new terraphim_automata API
587-
// is_all_terms_connected_by_path no longer exists
588-
// let all_connected = is_all_terms_connected_by_path(concepts).map_err(|e| {
589-
// GoalAlignmentError::KnowledgeGraphError(format!("Failed to check connectivity: {}", e))
590-
// })?;
591-
592-
// Temporary fallback: assume concepts are connected
593-
let all_connected = true;
593+
// Use the role graph to check whether the goal's concepts are connected
594+
// by a path. The free `is_all_terms_connected_by_path` function was
595+
// removed during the extraction, but `RoleGraph` exposes the same check.
596+
let all_connected = self
597+
.role_graph
598+
.is_all_terms_connected_by_path(&concepts.join(" "));
594599

595600
// For now, create a simplified connectivity result
596601
let connectivity_result = ConnectivityResult {

crates/terraphim_multi_agent/benches/agent_operations.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ fn bench_command_processing(c: &mut Criterion) {
7474
}
7575
}
7676

77-
/// Benchmark agent registry operations (DISABLED during migration)
78-
#[allow(dead_code)]
79-
fn _bench_registry_operations(_c: &mut Criterion) {
80-
// TODO: Migrate to KnowledgeGraphAgentRegistry
81-
// This benchmark is temporarily disabled during the registry migration.
82-
// Re-enable after implementing KnowledgeGraphAgentRegistry benchmarks.
83-
}
84-
8577
/// Benchmark memory operations
8678
fn bench_memory_operations(c: &mut Criterion) {
8779
let rt = Runtime::new().unwrap();
@@ -347,7 +339,6 @@ criterion_group!(
347339
bench_agent_creation,
348340
bench_agent_initialization,
349341
bench_command_processing,
350-
// bench_registry_operations, // TODO: Re-enable after KG registry migration
351342
bench_memory_operations,
352343
bench_batch_operations,
353344
bench_concurrent_operations,

crates/terraphim_multi_agent/src/agent.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ impl TerraphimAgent {
294294

295295
/// Initialize the agent and load any persisted state
296296
pub async fn initialize(&self) -> MultiAgentResult<()> {
297-
// Try to load existing state from persistence
298-
// TODO: Implement proper state loading with interior mutability
299-
// self.load_state().await?;
300-
301297
// Set up system context
302298
self.setup_system_context().await?;
303299

@@ -482,54 +478,6 @@ impl TerraphimAgent {
482478
Ok(())
483479
}
484480

485-
/// Load agent state from persistence
486-
#[allow(dead_code)]
487-
async fn load_state(&self) -> MultiAgentResult<()> {
488-
let key = format!("agent_state:{}", self.agent_id);
489-
490-
match self.persistence.fastest_op.read(&key).await {
491-
Ok(data) => {
492-
let state: AgentState = serde_json::from_slice(&data.to_vec())
493-
.map_err(MultiAgentError::SerializationError)?;
494-
495-
// Restore state
496-
// TODO: Implement proper state loading with interior mutability
497-
// self.goals = state.goals;
498-
*self.status.write().await = state.status;
499-
// self.created_at = state.created_at;
500-
*self.last_active.write().await = state.last_active;
501-
502-
// Restore evolution components
503-
{
504-
let _memory = self.memory.write().await;
505-
// TODO: Implement state restoration
506-
// *memory = VersionedMemory::from_snapshot(state.memory_snapshot);
507-
}
508-
{
509-
let _tasks = self.tasks.write().await;
510-
// TODO: Implement state restoration
511-
// *tasks = VersionedTaskList::from_state(state.tasks_snapshot);
512-
}
513-
{
514-
let _lessons = self.lessons.write().await;
515-
// TODO: Implement state restoration
516-
// *lessons = VersionedLessons::from_lessons(state.lessons_snapshot);
517-
}
518-
519-
log::info!("Loaded existing state for agent {}", self.agent_id);
520-
}
521-
Err(ref e) => {
522-
log::info!(
523-
"No existing state found for agent {} ({})",
524-
self.agent_id,
525-
e
526-
);
527-
}
528-
}
529-
530-
Ok(())
531-
}
532-
533481
/// Set up initial system context
534482
async fn setup_system_context(&self) -> MultiAgentResult<()> {
535483
let mut context = self.context.write().await;

crates/terraphim_multi_agent/src/agents/ontology_agents.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ Respond with ONLY valid JSON array:
338338
let response = client.generate(request).await?;
339339

340340
#[derive(Deserialize)]
341-
#[allow(dead_code)]
342341
struct ReviewSuggestion {
343342
original: String,
344343
suggested_uri: Option<String>,
@@ -349,6 +348,14 @@ Respond with ONLY valid JSON array:
349348

350349
if let Ok(suggestions) = serde_json::from_str::<Vec<ReviewSuggestion>>(&response.content) {
351350
for suggestion in suggestions {
351+
if let Some(reason) = &suggestion.reason {
352+
log::debug!(
353+
"Review suggestion for '{}' (confidence {:.2}): {}",
354+
suggestion.original,
355+
suggestion.confidence,
356+
reason
357+
);
358+
}
352359
if let Some(entity) = entities
353360
.iter_mut()
354361
.find(|e| e.raw_value == suggestion.original)

0 commit comments

Comments
 (0)