11/// Handle `rsh --install claude`: register MCP server and install SessionStart hook.
2- use serde_json:: { json , Value } ;
2+ use serde_json:: { Value , json } ;
33
44fn read_json_file ( path : & std:: path:: Path ) -> Value {
55 match std:: fs:: read_to_string ( path) {
@@ -23,11 +23,7 @@ fn write_json_file(path: &std::path::Path, value: &Value) {
2323 }
2424}
2525
26- fn install_mcp_server (
27- project_root : & std:: path:: Path ,
28- allow_redirects : bool ,
29- inherit_env : bool ,
30- ) {
26+ fn install_mcp_server ( project_root : & std:: path:: Path , allow_redirects : bool , inherit_env : bool ) {
3127 let mcp_path = project_root. join ( ".mcp.json" ) ;
3228
3329 let mut args = vec ! [ "--mcp" . to_string( ) ] ;
@@ -51,7 +47,10 @@ fn install_mcp_server(
5147 } ;
5248 let servers = root. entry ( "mcpServers" ) . or_insert_with ( || json ! ( { } ) ) ;
5349 let Some ( servers) = servers. as_object_mut ( ) else {
54- eprintln ! ( "error: mcpServers in {} must be a JSON object" , mcp_path. display( ) ) ;
50+ eprintln ! (
51+ "error: mcpServers in {} must be a JSON object" ,
52+ mcp_path. display( )
53+ ) ;
5554 std:: process:: exit ( 1 ) ;
5655 } ;
5756 servers. insert ( "rsh" . to_string ( ) , rsh_entry) ;
@@ -71,29 +70,41 @@ fn install_session_hook(project_root: &std::path::Path) {
7170 let mut settings = read_json_file ( & settings_path) ;
7271
7372 let Some ( root) = settings. as_object_mut ( ) else {
74- eprintln ! ( "error: {} must contain a JSON object" , settings_path. display( ) ) ;
73+ eprintln ! (
74+ "error: {} must contain a JSON object" ,
75+ settings_path. display( )
76+ ) ;
7577 std:: process:: exit ( 1 ) ;
7678 } ;
7779 let hooks = root. entry ( "hooks" ) . or_insert_with ( || json ! ( { } ) ) ;
7880 let Some ( hooks) = hooks. as_object_mut ( ) else {
79- eprintln ! ( "error: hooks in {} must be a JSON object" , settings_path. display( ) ) ;
81+ eprintln ! (
82+ "error: hooks in {} must be a JSON object" ,
83+ settings_path. display( )
84+ ) ;
8085 std:: process:: exit ( 1 ) ;
8186 } ;
8287 let session_start = hooks. entry ( "SessionStart" ) . or_insert_with ( || json ! ( [ ] ) ) ;
8388 let Some ( arr) = session_start. as_array_mut ( ) else {
84- eprintln ! ( "error: SessionStart in {} must be an array" , settings_path. display( ) ) ;
89+ eprintln ! (
90+ "error: SessionStart in {} must be an array" ,
91+ settings_path. display( )
92+ ) ;
8593 std:: process:: exit ( 1 ) ;
8694 } ;
8795
8896 // Dedup: don't add a second hook if one already exists
8997 let already_exists = arr. iter ( ) . any ( |entry| {
90- entry. get ( "hooks" ) . and_then ( |h| h. as_array ( ) ) . is_some_and ( |hooks_arr| {
91- hooks_arr. iter ( ) . any ( |hook| {
92- hook. get ( "command" )
93- . and_then ( |c| c. as_str ( ) )
94- . is_some_and ( |c| c. contains ( "rsh --prime" ) )
98+ entry
99+ . get ( "hooks" )
100+ . and_then ( |h| h. as_array ( ) )
101+ . is_some_and ( |hooks_arr| {
102+ hooks_arr. iter ( ) . any ( |hook| {
103+ hook. get ( "command" )
104+ . and_then ( |c| c. as_str ( ) )
105+ . is_some_and ( |c| c. contains ( "rsh --prime" ) )
106+ } )
95107 } )
96- } )
97108 } ) ;
98109
99110 if !already_exists {
@@ -107,11 +118,7 @@ fn install_session_hook(project_root: &std::path::Path) {
107118 eprintln ! ( " SessionStart hook: {}" , settings_path. display( ) ) ;
108119}
109120
110- pub fn install_claude (
111- working_dir : Option < & str > ,
112- allow_redirects : bool ,
113- inherit_env : bool ,
114- ) {
121+ pub fn install_claude ( working_dir : Option < & str > , allow_redirects : bool , inherit_env : bool ) {
115122 let start_dir = crate :: resolve_working_dir ( working_dir) ;
116123 let project_root = crate :: find_git_root ( & start_dir) . unwrap_or ( start_dir) ;
117124
0 commit comments