@@ -96,6 +96,8 @@ const CODEX_ENV_METADATA_KEY: &str = "desktop_codex_env";
9696const CLAUDE_OAUTH_ENV : & str = "CLAUDE_CODE_OAUTH_TOKEN" ;
9797const CODEX_API_KEY_ENV : & str = "OPENAI_API_KEY" ;
9898const GITHUB_RELEASE_REPO : & str = "Pyiner/garyx" ;
99+ #[ cfg( any( target_os = "macos" , test) ) ]
100+ const MACOS_CLI_CODESIGN_IDENTIFIER : & str = "com.bytedance.garyx" ;
99101const DEFAULT_CHANNEL_AGENT_ID : & str = "claude" ;
100102
101103#[ derive( Debug , Deserialize ) ]
@@ -169,6 +171,45 @@ fn replacement_binary_path(
169171 Ok ( std:: env:: current_exe ( ) ?)
170172}
171173
174+ #[ cfg( any( target_os = "macos" , test) ) ]
175+ fn macos_cli_codesign_args ( binary_path : & Path ) -> Vec < std:: ffi:: OsString > {
176+ let mut args = vec ! [
177+ std:: ffi:: OsString :: from( "--force" ) ,
178+ std:: ffi:: OsString :: from( "--sign" ) ,
179+ std:: ffi:: OsString :: from( "-" ) ,
180+ std:: ffi:: OsString :: from( "--identifier" ) ,
181+ std:: ffi:: OsString :: from( MACOS_CLI_CODESIGN_IDENTIFIER ) ,
182+ ] ;
183+ args. push ( binary_path. as_os_str ( ) . to_os_string ( ) ) ;
184+ args
185+ }
186+
187+ #[ cfg( target_os = "macos" ) ]
188+ fn ad_hoc_codesign_macos_binary ( binary_path : & Path ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
189+ let output = std:: process:: Command :: new ( "/usr/bin/codesign" )
190+ . args ( macos_cli_codesign_args ( binary_path) )
191+ . output ( ) ?;
192+ if output. status . success ( ) {
193+ return Ok ( ( ) ) ;
194+ }
195+
196+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
197+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
198+ Err ( format ! (
199+ "codesign failed for {} with identifier {}: {}{}" ,
200+ binary_path. display( ) ,
201+ MACOS_CLI_CODESIGN_IDENTIFIER ,
202+ stdout,
203+ stderr
204+ )
205+ . into ( ) )
206+ }
207+
208+ #[ cfg( not( target_os = "macos" ) ) ]
209+ fn ad_hoc_codesign_macos_binary ( _binary_path : & Path ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
210+ Ok ( ( ) )
211+ }
212+
172213fn register_plugin_state_logging ( plugin_manager : & mut ChannelPluginManager ) {
173214 plugin_manager. register_state_hook ( |status| {
174215 tracing:: info!(
@@ -1223,6 +1264,7 @@ pub(crate) async fn cmd_update(
12231264 perms. set_mode ( 0o755 ) ;
12241265 fs:: set_permissions ( & staged_path, perms) ?;
12251266 }
1267+ ad_hoc_codesign_macos_binary ( & staged_path) ?;
12261268 fs:: rename ( & staged_path, & destination) ?;
12271269
12281270 println ! (
0 commit comments