@@ -259,53 +259,6 @@ pub fn sync_shared_agent_data(app: &tauri::AppHandle) {
259259 }
260260}
261261
262- fn reconcile_mcp_commands_in_file ( path : & Path ) {
263- patch_json_records ( path, |obj| {
264- let agent_command = match obj. get ( "agent_command" ) . and_then ( |v| v. as_str ( ) ) {
265- Some ( cmd) => cmd. to_string ( ) ,
266- None => return false ,
267- } ;
268- let Some ( runtime) = crate :: managed_agents:: known_acp_runtime ( & agent_command) else {
269- return false ;
270- } ;
271- let expected = runtime. mcp_command . unwrap_or ( "" ) ;
272- let current = obj
273- . get ( "mcp_command" )
274- . and_then ( |v| v. as_str ( ) )
275- . unwrap_or ( "" ) ;
276- // Only clear the known stale default — never touch user-customized values.
277- if current == "sprout-mcp-server" {
278- eprintln ! (
279- "sprout-desktop: runtime-reconcile: {:?} ({:?}): mcp_command {:?} → {:?}" ,
280- obj. get( "name" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "?" ) ,
281- agent_command,
282- current,
283- expected,
284- ) ;
285- obj. insert (
286- "mcp_command" . to_string ( ) ,
287- serde_json:: Value :: String ( expected. to_string ( ) ) ,
288- ) ;
289- true
290- } else {
291- false
292- }
293- } ) ;
294- }
295-
296- /// Reconcile `mcp_command` values in managed-agents.json against the
297- /// discovery table. Known runtimes get their canonical mcp_command;
298- /// unknown/custom agents are left untouched.
299- pub fn reconcile_provider_mcp_commands ( app : & tauri:: AppHandle ) {
300- let Ok ( dir) = app. path ( ) . app_data_dir ( ) else {
301- return ;
302- } ;
303- let path = dir. join ( "agents/managed-agents.json" ) ;
304- if !path. exists ( ) {
305- return ;
306- }
307- reconcile_mcp_commands_in_file ( & path) ;
308- }
309262
310263fn reconcile_pack_paths_in_file ( path : & Path , canonical_dir : & Path ) {
311264 let canonical_packs = canonical_dir. join ( "agents/packs" ) ;
@@ -686,161 +639,6 @@ mod tests {
686639 serde_json:: from_str ( & content) . unwrap ( )
687640 }
688641
689- #[ test]
690- fn reconcile_clears_mcp_command_for_goose ( ) {
691- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
692- write_agents_json (
693- dir. path ( ) ,
694- & serde_json:: json!( [ {
695- "name" : "Scout" ,
696- "agent_command" : "goose" ,
697- "mcp_command" : "sprout-mcp-server"
698- } ] ) ,
699- ) ;
700- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
701- let records = read_agents_json ( dir. path ( ) ) ;
702- assert_eq ! ( records[ 0 ] [ "mcp_command" ] , "" ) ;
703- }
704-
705- #[ test]
706- fn reconcile_clears_mcp_command_for_claude ( ) {
707- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
708- write_agents_json (
709- dir. path ( ) ,
710- & serde_json:: json!( [ {
711- "name" : "Claude Agent" ,
712- "agent_command" : "claude-agent-acp" ,
713- "mcp_command" : "sprout-mcp-server"
714- } ] ) ,
715- ) ;
716- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
717- let records = read_agents_json ( dir. path ( ) ) ;
718- assert_eq ! ( records[ 0 ] [ "mcp_command" ] , "" ) ;
719- }
720-
721- #[ test]
722- fn reconcile_preserves_sprout_dev_mcp ( ) {
723- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
724- write_agents_json (
725- dir. path ( ) ,
726- & serde_json:: json!( [ {
727- "name" : "Solo" ,
728- "agent_command" : "sprout-agent" ,
729- "mcp_command" : "sprout-dev-mcp"
730- } ] ) ,
731- ) ;
732- let before =
733- std:: fs:: read_to_string ( dir. path ( ) . join ( "agents/managed-agents.json" ) ) . unwrap ( ) ;
734- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
735- let after = std:: fs:: read_to_string ( dir. path ( ) . join ( "agents/managed-agents.json" ) ) . unwrap ( ) ;
736- assert_eq ! (
737- before, after,
738- "file should not be rewritten when already correct"
739- ) ;
740- }
741-
742- #[ test]
743- fn reconcile_fixes_sprout_agent_if_stale ( ) {
744- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
745- write_agents_json (
746- dir. path ( ) ,
747- & serde_json:: json!( [ {
748- "name" : "Solo" ,
749- "agent_command" : "sprout-agent" ,
750- "mcp_command" : "sprout-mcp-server"
751- } ] ) ,
752- ) ;
753- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
754- let records = read_agents_json ( dir. path ( ) ) ;
755- assert_eq ! ( records[ 0 ] [ "mcp_command" ] , "sprout-dev-mcp" ) ;
756- }
757-
758- #[ test]
759- fn reconcile_leaves_unknown_agent_untouched ( ) {
760- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
761- write_agents_json (
762- dir. path ( ) ,
763- & serde_json:: json!( [ {
764- "name" : "Custom Bot" ,
765- "agent_command" : "my-custom-agent" ,
766- "mcp_command" : "my-custom-mcp"
767- } ] ) ,
768- ) ;
769- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
770- let records = read_agents_json ( dir. path ( ) ) ;
771- assert_eq ! ( records[ 0 ] [ "mcp_command" ] , "my-custom-mcp" ) ;
772- }
773-
774- #[ test]
775- fn reconcile_is_idempotent ( ) {
776- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
777- write_agents_json (
778- dir. path ( ) ,
779- & serde_json:: json!( [ {
780- "name" : "Scout" ,
781- "agent_command" : "goose" ,
782- "mcp_command" : "sprout-mcp-server"
783- } ] ) ,
784- ) ;
785- let path = dir. path ( ) . join ( "agents/managed-agents.json" ) ;
786- reconcile_mcp_commands_in_file ( & path) ;
787- let after_first = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
788- reconcile_mcp_commands_in_file ( & path) ;
789- let after_second = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
790- assert_eq ! ( after_first, after_second) ;
791- }
792-
793- #[ test]
794- fn reconcile_handles_mixed_records ( ) {
795- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
796- write_agents_json (
797- dir. path ( ) ,
798- & serde_json:: json!( [
799- { "name" : "Scout" , "agent_command" : "goose" , "mcp_command" : "sprout-mcp-server" } ,
800- { "name" : "Claude" , "agent_command" : "claude-agent-acp" , "mcp_command" : "sprout-mcp-server" } ,
801- { "name" : "Solo" , "agent_command" : "sprout-agent" , "mcp_command" : "sprout-dev-mcp" } ,
802- { "name" : "Custom" , "agent_command" : "my-bot" , "mcp_command" : "my-mcp" } ,
803- { "name" : "Codex" , "agent_command" : "codex-acp" , "mcp_command" : "sprout-mcp-server" }
804- ] ) ,
805- ) ;
806- reconcile_mcp_commands_in_file ( & dir. path ( ) . join ( "agents/managed-agents.json" ) ) ;
807- let records = read_agents_json ( dir. path ( ) ) ;
808- assert_eq ! ( records[ 0 ] [ "mcp_command" ] , "" , "goose should be cleared" ) ;
809- assert_eq ! ( records[ 1 ] [ "mcp_command" ] , "" , "claude should be cleared" ) ;
810- assert_eq ! (
811- records[ 2 ] [ "mcp_command" ] , "sprout-dev-mcp" ,
812- "sprout-agent preserved"
813- ) ;
814- assert_eq ! (
815- records[ 3 ] [ "mcp_command" ] , "my-mcp" ,
816- "custom agent untouched"
817- ) ;
818- assert_eq ! ( records[ 4 ] [ "mcp_command" ] , "" , "codex should be cleared" ) ;
819- }
820-
821- #[ test]
822- fn reconcile_leaves_absent_mcp_command_untouched ( ) {
823- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
824- let json = serde_json:: json!( [ { "name" : "Solo" , "agent_command" : "sprout-agent" } ] ) ;
825- write_agents_json ( dir. path ( ) , & json) ;
826- let path = dir. path ( ) . join ( "agents/managed-agents.json" ) ;
827- let before = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
828- reconcile_mcp_commands_in_file ( & path) ;
829- assert_eq ! ( before, std:: fs:: read_to_string( & path) . unwrap( ) ) ;
830- }
831-
832- #[ test]
833- fn reconcile_leaves_null_mcp_command_untouched ( ) {
834- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
835- let json =
836- serde_json:: json!( [ { "name" : "Solo" , "agent_command" : "sprout-agent" , "mcp_command" : null} ] ) ;
837- write_agents_json ( dir. path ( ) , & json) ;
838- let path = dir. path ( ) . join ( "agents/managed-agents.json" ) ;
839- let before = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
840- reconcile_mcp_commands_in_file ( & path) ;
841- assert_eq ! ( before, std:: fs:: read_to_string( & path) . unwrap( ) ) ;
842- }
843-
844642 #[ test]
845643 fn sync_creates_packs_directory_symlink ( ) {
846644 let ( _parent, canonical, worktree) = setup_sync_layout ( ) ;
0 commit comments