From 58bb9fa9a7a60fb798aaae80ecfed48d325f05c7 Mon Sep 17 00:00:00 2001 From: Syeda Anshrah Gillani Date: Wed, 18 Feb 2026 17:34:20 +0500 Subject: [PATCH] refactor: sort HashMap keys for deterministic output in identity and doctor --- src/doctor/mod.rs | 5 ++++- src/identity.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/doctor/mod.rs b/src/doctor/mod.rs index 6db91fc..c5367c0 100644 --- a/src/doctor/mod.rs +++ b/src/doctor/mod.rs @@ -241,7 +241,10 @@ fn check_config_semantics(config: &Config, items: &mut Vec) { } // Delegate agents: provider validity - for (name, agent) in &config.agents { + let mut agent_names: Vec<_> = config.agents.keys().collect(); + agent_names.sort(); + for name in agent_names { + let agent = config.agents.get(name).unwrap(); if let Some(reason) = provider_validation_error(&agent.provider) { items.push(DiagItem::warn( cat, diff --git a/src/identity.rs b/src/identity.rs index 32cf08c..a614e46 100644 --- a/src/identity.rs +++ b/src/identity.rs @@ -783,7 +783,10 @@ pub fn aieos_to_system_prompt(identity: &AieosIdentity) -> String { if let Some(ref matrix) = psych.neural_matrix { if !matrix.is_empty() { prompt.push_str("\n**Neural Matrix (Cognitive Weights):**\n"); - for (trait_name, weight) in matrix { + let mut sorted_keys: Vec<_> = matrix.keys().collect(); + sorted_keys.sort(); + for trait_name in sorted_keys { + let weight = matrix.get(trait_name).unwrap(); let _ = writeln!(prompt, "- {}: {:.2}", trait_name, weight); } } @@ -952,7 +955,10 @@ pub fn aieos_to_system_prompt(identity: &AieosIdentity) -> String { if let Some(ref favorites) = interests.favorites { if !favorites.is_empty() { prompt.push_str("\n**Favorites:**\n"); - for (category, value) in favorites { + let mut sorted_keys: Vec<_> = favorites.keys().collect(); + sorted_keys.sort(); + for category in sorted_keys { + let value = favorites.get(category).unwrap(); let _ = writeln!(prompt, "- {}: {}", category, value); } }