diff --git a/crates/openfang-api/src/routes.rs b/crates/openfang-api/src/routes.rs index 14a2debfe4..ba7690c3a3 100644 --- a/crates/openfang-api/src/routes.rs +++ b/crates/openfang-api/src/routes.rs @@ -6287,7 +6287,7 @@ pub async fn list_providers(State(state): State>) -> impl IntoResp // Index probe results by provider list position for O(1) lookup let mut probe_map: HashMap = HashMap::with_capacity(local_providers.len()); - for ((idx, _, _), result) in local_providers.iter().zip(probe_results.into_iter()) { + for ((idx, _, _), result) in local_providers.iter().zip(probe_results) { probe_map.insert(*idx, result); } diff --git a/crates/openfang-channels/src/irc.rs b/crates/openfang-channels/src/irc.rs index b05a59f91d..a9b87e46b3 100644 --- a/crates/openfang-channels/src/irc.rs +++ b/crates/openfang-channels/src/irc.rs @@ -326,19 +326,17 @@ impl ChannelAdapter for IrcAdapter { } // RPL_WELCOME (001) — registration complete, join channels - "001" => { - if !joined { - info!("IRC registered as {nick_clone}"); - for ch in &channels_clone { - let join_cmd = format!("JOIN {ch}\r\n"); - if let Err(e) = writer.write_all(join_cmd.as_bytes()).await { - warn!("IRC JOIN send failed: {e}"); - break 'inner true; - } - info!("IRC joining {ch}"); + "001" if !joined => { + info!("IRC registered as {nick_clone}"); + for ch in &channels_clone { + let join_cmd = format!("JOIN {ch}\r\n"); + if let Err(e) = writer.write_all(join_cmd.as_bytes()).await { + warn!("IRC JOIN send failed: {e}"); + break 'inner true; } - joined = true; + info!("IRC joining {ch}"); } + joined = true; } // PRIVMSG — incoming message diff --git a/crates/openfang-cli/src/tui/screens/agents.rs b/crates/openfang-cli/src/tui/screens/agents.rs index 9121dc938f..fe1a92bdc0 100644 --- a/crates/openfang-cli/src/tui/screens/agents.rs +++ b/crates/openfang-cli/src/tui/screens/agents.rs @@ -576,13 +576,11 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::CreateMethod; } - KeyCode::Enter => { - if !self.custom_name.is_empty() { - if self.custom_desc.is_empty() { - self.custom_desc = format!("A custom {} agent", self.custom_name); - } - self.sub = AgentSubScreen::CustomDesc; + KeyCode::Enter if !self.custom_name.is_empty() => { + if self.custom_desc.is_empty() { + self.custom_desc = format!("A custom {} agent", self.custom_name); } + self.sub = AgentSubScreen::CustomDesc; } KeyCode::Char(c) => { self.custom_name.push(c); @@ -641,15 +639,11 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::CustomPrompt; } - KeyCode::Up | KeyCode::Char('k') => { - if self.tool_cursor > 0 { - self.tool_cursor -= 1; - } + KeyCode::Up | KeyCode::Char('k') if self.tool_cursor > 0 => { + self.tool_cursor -= 1; } - KeyCode::Down | KeyCode::Char('j') => { - if self.tool_cursor < TOOL_OPTIONS.len() - 1 { - self.tool_cursor += 1; - } + KeyCode::Down | KeyCode::Char('j') if self.tool_cursor < TOOL_OPTIONS.len() - 1 => { + self.tool_cursor += 1; } KeyCode::Char(' ') => { self.tool_checks[self.tool_cursor] = !self.tool_checks[self.tool_cursor]; @@ -674,21 +668,15 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::CustomTools; } - KeyCode::Up | KeyCode::Char('k') => { - if self.skill_cursor > 0 { - self.skill_cursor -= 1; - } + KeyCode::Up | KeyCode::Char('k') if self.skill_cursor > 0 => { + self.skill_cursor -= 1; } - KeyCode::Down | KeyCode::Char('j') => { - if len > 0 && self.skill_cursor < len - 1 { - self.skill_cursor += 1; - } + KeyCode::Down | KeyCode::Char('j') if len > 0 && self.skill_cursor < len - 1 => { + self.skill_cursor += 1; } - KeyCode::Char(' ') => { - if len > 0 { - let checked = &mut self.available_skills[self.skill_cursor].1; - *checked = !*checked; - } + KeyCode::Char(' ') if len > 0 => { + let checked = &mut self.available_skills[self.skill_cursor].1; + *checked = !*checked; } KeyCode::Enter => { // Advance to MCP server selection @@ -706,21 +694,15 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::CustomSkills; } - KeyCode::Up | KeyCode::Char('k') => { - if self.mcp_cursor > 0 { - self.mcp_cursor -= 1; - } + KeyCode::Up | KeyCode::Char('k') if self.mcp_cursor > 0 => { + self.mcp_cursor -= 1; } - KeyCode::Down | KeyCode::Char('j') => { - if len > 0 && self.mcp_cursor < len - 1 { - self.mcp_cursor += 1; - } + KeyCode::Down | KeyCode::Char('j') if len > 0 && self.mcp_cursor < len - 1 => { + self.mcp_cursor += 1; } - KeyCode::Char(' ') => { - if len > 0 { - let checked = &mut self.available_mcp[self.mcp_cursor].1; - *checked = !*checked; - } + KeyCode::Char(' ') if len > 0 => { + let checked = &mut self.available_mcp[self.mcp_cursor].1; + *checked = !*checked; } KeyCode::Enter => { let toml = self.build_custom_toml(); @@ -737,21 +719,15 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::AgentDetail; } - KeyCode::Up | KeyCode::Char('k') => { - if self.skill_cursor > 0 { - self.skill_cursor -= 1; - } + KeyCode::Up | KeyCode::Char('k') if self.skill_cursor > 0 => { + self.skill_cursor -= 1; } - KeyCode::Down | KeyCode::Char('j') => { - if len > 0 && self.skill_cursor < len - 1 { - self.skill_cursor += 1; - } + KeyCode::Down | KeyCode::Char('j') if len > 0 && self.skill_cursor < len - 1 => { + self.skill_cursor += 1; } - KeyCode::Char(' ') => { - if len > 0 { - let checked = &mut self.available_skills[self.skill_cursor].1; - *checked = !*checked; - } + KeyCode::Char(' ') if len > 0 => { + let checked = &mut self.available_skills[self.skill_cursor].1; + *checked = !*checked; } KeyCode::Enter => { // Save — collect checked skill names (none checked = "all") @@ -780,21 +756,15 @@ impl AgentSelectState { KeyCode::Esc => { self.sub = AgentSubScreen::AgentDetail; } - KeyCode::Up | KeyCode::Char('k') => { - if self.mcp_cursor > 0 { - self.mcp_cursor -= 1; - } + KeyCode::Up | KeyCode::Char('k') if self.mcp_cursor > 0 => { + self.mcp_cursor -= 1; } - KeyCode::Down | KeyCode::Char('j') => { - if len > 0 && self.mcp_cursor < len - 1 { - self.mcp_cursor += 1; - } + KeyCode::Down | KeyCode::Char('j') if len > 0 && self.mcp_cursor < len - 1 => { + self.mcp_cursor += 1; } - KeyCode::Char(' ') => { - if len > 0 { - let checked = &mut self.available_mcp[self.mcp_cursor].1; - *checked = !*checked; - } + KeyCode::Char(' ') if len > 0 => { + let checked = &mut self.available_mcp[self.mcp_cursor].1; + *checked = !*checked; } KeyCode::Enter => { // Save — collect checked server names (none checked = "all") diff --git a/crates/openfang-cli/src/tui/screens/audit.rs b/crates/openfang-cli/src/tui/screens/audit.rs index f7aa453797..2a0430fa74 100644 --- a/crates/openfang-cli/src/tui/screens/audit.rs +++ b/crates/openfang-cli/src/tui/screens/audit.rs @@ -164,19 +164,15 @@ impl AuditState { let total = self.filtered.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.list_state.select(Some(next)); } KeyCode::Char('f') => { self.action_filter = self.action_filter.next(); diff --git a/crates/openfang-cli/src/tui/screens/comms.rs b/crates/openfang-cli/src/tui/screens/comms.rs index b0a5b84b28..4ea61d0b57 100644 --- a/crates/openfang-cli/src/tui/screens/comms.rs +++ b/crates/openfang-cli/src/tui/screens/comms.rs @@ -155,19 +155,19 @@ impl CommsState { self.task_field = 0; } KeyCode::Char('r') => return CommsAction::Refresh, - KeyCode::Up | KeyCode::Char('k') => { - if self.focus == CommsFocus::EventList && !self.events.is_empty() { - let i = self.event_list_state.selected().unwrap_or(0); - let next = if i == 0 { self.events.len() - 1 } else { i - 1 }; - self.event_list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') + if self.focus == CommsFocus::EventList && !self.events.is_empty() => + { + let i = self.event_list_state.selected().unwrap_or(0); + let next = if i == 0 { self.events.len() - 1 } else { i - 1 }; + self.event_list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if self.focus == CommsFocus::EventList && !self.events.is_empty() { - let i = self.event_list_state.selected().unwrap_or(0); - let next = (i + 1) % self.events.len(); - self.event_list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') + if self.focus == CommsFocus::EventList && !self.events.is_empty() => + { + let i = self.event_list_state.selected().unwrap_or(0); + let next = (i + 1) % self.events.len(); + self.event_list_state.select(Some(next)); } _ => {} } @@ -189,18 +189,17 @@ impl CommsState { self.send_field - 1 }; } - KeyCode::Enter => { + KeyCode::Enter if !self.send_from.is_empty() && !self.send_to.is_empty() - && !self.send_msg.is_empty() - { - self.show_send_modal = false; - return CommsAction::SendMessage { - from: self.send_from.clone(), - to: self.send_to.clone(), - msg: self.send_msg.clone(), - }; - } + && !self.send_msg.is_empty() => + { + self.show_send_modal = false; + return CommsAction::SendMessage { + from: self.send_from.clone(), + to: self.send_to.clone(), + msg: self.send_msg.clone(), + }; } KeyCode::Char(c) => match self.send_field { 0 => self.send_from.push(c), @@ -238,15 +237,13 @@ impl CommsState { self.task_field - 1 }; } - KeyCode::Enter => { - if !self.task_title.is_empty() { - self.show_task_modal = false; - return CommsAction::PostTask { - title: self.task_title.clone(), - desc: self.task_desc.clone(), - assign: self.task_assign.clone(), - }; - } + KeyCode::Enter if !self.task_title.is_empty() => { + self.show_task_modal = false; + return CommsAction::PostTask { + title: self.task_title.clone(), + desc: self.task_desc.clone(), + assign: self.task_assign.clone(), + }; } KeyCode::Char(c) => match self.task_field { 0 => self.task_title.push(c), diff --git a/crates/openfang-cli/src/tui/screens/extensions.rs b/crates/openfang-cli/src/tui/screens/extensions.rs index f3f65fe2c5..7ba69a6fba 100644 --- a/crates/openfang-cli/src/tui/screens/extensions.rs +++ b/crates/openfang-cli/src/tui/screens/extensions.rs @@ -152,12 +152,10 @@ impl ExtensionsState { self.sub = ExtSub::Health; return ExtensionsAction::RefreshHealth; } - KeyCode::Char('/') => { - if self.sub == ExtSub::Browse { - self.searching = true; - self.search_query.clear(); - return ExtensionsAction::Continue; - } + KeyCode::Char('/') if self.sub == ExtSub::Browse => { + self.searching = true; + self.search_query.clear(); + return ExtensionsAction::Continue; } _ => {} } @@ -172,19 +170,15 @@ impl ExtensionsState { fn handle_browse(&mut self, key: KeyEvent) -> ExtensionsAction { let total = self.filtered().len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.browse_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.browse_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.browse_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.browse_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.browse_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.browse_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.browse_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.browse_list.select(Some(next)); } KeyCode::Enter => { let filtered = self.filtered(); @@ -222,24 +216,18 @@ impl ExtensionsState { let total = self.installed_list_data().len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.installed_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.installed_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.installed_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.installed_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.installed_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.installed_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.installed_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.installed_list.select(Some(next)); } - KeyCode::Char('d') | KeyCode::Delete => { - if self.installed_list.selected().is_some() { - self.confirm_remove = true; - } + KeyCode::Char('d') | KeyCode::Delete if self.installed_list.selected().is_some() => { + self.confirm_remove = true; } KeyCode::Char('r') => return ExtensionsAction::RefreshAll, _ => {} @@ -250,19 +238,15 @@ impl ExtensionsState { fn handle_health(&mut self, key: KeyEvent) -> ExtensionsAction { let total = self.health_entries.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.health_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.health_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.health_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.health_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.health_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.health_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.health_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.health_list.select(Some(next)); } KeyCode::Char('r') | KeyCode::Enter => { if let Some(sel) = self.health_list.selected() { diff --git a/crates/openfang-cli/src/tui/screens/hands.rs b/crates/openfang-cli/src/tui/screens/hands.rs index b5559c5150..52c0aef2c9 100644 --- a/crates/openfang-cli/src/tui/screens/hands.rs +++ b/crates/openfang-cli/src/tui/screens/hands.rs @@ -109,19 +109,15 @@ impl HandsState { fn handle_marketplace(&mut self, key: KeyEvent) -> HandsAction { let total = self.definitions.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.marketplace_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.marketplace_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.marketplace_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.marketplace_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.marketplace_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.marketplace_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.marketplace_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.marketplace_list.select(Some(next)); } KeyCode::Enter | KeyCode::Char('a') => { if let Some(sel) = self.marketplace_list.selected() { @@ -157,24 +153,18 @@ impl HandsState { let total = self.instances.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.active_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.active_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.active_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.active_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.active_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.active_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.active_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.active_list.select(Some(next)); } - KeyCode::Char('d') | KeyCode::Delete => { - if self.active_list.selected().is_some() { - self.confirm_deactivate = true; - } + KeyCode::Char('d') | KeyCode::Delete if self.active_list.selected().is_some() => { + self.confirm_deactivate = true; } KeyCode::Char('p') => { if let Some(sel) = self.active_list.selected() { diff --git a/crates/openfang-cli/src/tui/screens/init_wizard.rs b/crates/openfang-cli/src/tui/screens/init_wizard.rs index 7f256082ec..4d15a49f0c 100644 --- a/crates/openfang-cli/src/tui/screens/init_wizard.rs +++ b/crates/openfang-cli/src/tui/screens/init_wizard.rs @@ -966,16 +966,15 @@ pub fn run() -> InitResult { state.step = Step::Provider; } } - KeyCode::Enter => { + KeyCode::Enter if matches!( state.copilot_auth_status, CopilotAuthStatus::WaitingForUser - ) && !state.copilot_verification_uri.is_empty() - { - let _ = openfang_runtime::drivers::copilot::open_verification_url( - &state.copilot_verification_uri, - ); - } + ) && !state.copilot_verification_uri.is_empty() => + { + let _ = openfang_runtime::drivers::copilot::open_verification_url( + &state.copilot_verification_uri, + ); } _ => {} }, @@ -990,41 +989,36 @@ pub fn run() -> InitResult { state.key_test = KeyTestState::Idle; state.step = Step::Provider; } - KeyCode::Enter => { + KeyCode::Enter if !state.api_key_input.is_empty() - && state.key_test == KeyTestState::Idle - { - if let Some(p) = state.provider() { - let _ = crate::dotenv::save_env_key( - p.env_var, - &state.api_key_input, - ); - } - state.key_test = KeyTestState::Testing; - let provider_name = state - .provider() - .map(|p| p.name.to_string()) - .unwrap_or_default(); - let env_var = state - .provider() - .map(|p| p.env_var.to_string()) - .unwrap_or_default(); - let tx = test_tx.clone(); - std::thread::spawn(move || { - let ok = crate::test_api_key(&provider_name, &env_var); - let _ = tx.send(ok); - }); + && state.key_test == KeyTestState::Idle => + { + if let Some(p) = state.provider() { + let _ = crate::dotenv::save_env_key( + p.env_var, + &state.api_key_input, + ); } + state.key_test = KeyTestState::Testing; + let provider_name = state + .provider() + .map(|p| p.name.to_string()) + .unwrap_or_default(); + let env_var = state + .provider() + .map(|p| p.env_var.to_string()) + .unwrap_or_default(); + let tx = test_tx.clone(); + std::thread::spawn(move || { + let ok = crate::test_api_key(&provider_name, &env_var); + let _ = tx.send(ok); + }); } - KeyCode::Char(c) => { - if state.key_test == KeyTestState::Idle { - state.api_key_input.push(c); - } + KeyCode::Char(c) if state.key_test == KeyTestState::Idle => { + state.api_key_input.push(c); } - KeyCode::Backspace => { - if state.key_test == KeyTestState::Idle { - state.api_key_input.pop(); - } + KeyCode::Backspace if state.key_test == KeyTestState::Idle => { + state.api_key_input.pop(); } _ => {} } diff --git a/crates/openfang-cli/src/tui/screens/logs.rs b/crates/openfang-cli/src/tui/screens/logs.rs index 40b6656a21..64494c7a02 100644 --- a/crates/openfang-cli/src/tui/screens/logs.rs +++ b/crates/openfang-cli/src/tui/screens/logs.rs @@ -211,19 +211,15 @@ impl LogsState { let total = self.filtered.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.list_state.select(Some(next)); } KeyCode::Char('f') => { self.level_filter = self.level_filter.next(); @@ -237,15 +233,11 @@ impl LogsState { self.auto_refresh = !self.auto_refresh; } KeyCode::Char('r') => return LogsAction::Refresh, - KeyCode::End => { - if total > 0 { - self.list_state.select(Some(total - 1)); - } + KeyCode::End if total > 0 => { + self.list_state.select(Some(total - 1)); } - KeyCode::Home => { - if total > 0 { - self.list_state.select(Some(0)); - } + KeyCode::Home if total > 0 => { + self.list_state.select(Some(0)); } _ => {} } diff --git a/crates/openfang-cli/src/tui/screens/memory.rs b/crates/openfang-cli/src/tui/screens/memory.rs index cfa7b2da37..dc9a2d06cf 100644 --- a/crates/openfang-cli/src/tui/screens/memory.rs +++ b/crates/openfang-cli/src/tui/screens/memory.rs @@ -106,19 +106,15 @@ impl MemoryState { fn handle_agent_select(&mut self, key: KeyEvent) -> MemoryAction { let total = self.agents.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.agent_list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.agent_list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.agent_list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.agent_list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.agent_list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.agent_list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.agent_list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.agent_list_state.select(Some(next)); } KeyCode::Enter => { if let Some(sel) = self.agent_list_state.selected() { @@ -166,19 +162,15 @@ impl MemoryState { self.kv_pairs.clear(); self.selected_agent = None; } - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.kv_list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.kv_list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.kv_list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.kv_list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.kv_list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.kv_list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.kv_list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.kv_list_state.select(Some(next)); } KeyCode::Char('a') => { self.sub = MemorySub::AddKey; @@ -196,10 +188,8 @@ impl MemoryState { } } } - KeyCode::Char('d') => { - if self.kv_list_state.selected().is_some() { - self.confirm_delete = true; - } + KeyCode::Char('d') if self.kv_list_state.selected().is_some() => { + self.confirm_delete = true; } KeyCode::Char('r') => { if let Some(agent) = &self.selected_agent { diff --git a/crates/openfang-cli/src/tui/screens/peers.rs b/crates/openfang-cli/src/tui/screens/peers.rs index 3d3d8291ed..09354415c7 100644 --- a/crates/openfang-cli/src/tui/screens/peers.rs +++ b/crates/openfang-cli/src/tui/screens/peers.rs @@ -62,19 +62,15 @@ impl PeersState { } let total = self.peers.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.list_state.select(Some(next)); } KeyCode::Char('r') => return PeersAction::Refresh, _ => {} diff --git a/crates/openfang-cli/src/tui/screens/sessions.rs b/crates/openfang-cli/src/tui/screens/sessions.rs index 14bad4b675..091a3f85da 100644 --- a/crates/openfang-cli/src/tui/screens/sessions.rs +++ b/crates/openfang-cli/src/tui/screens/sessions.rs @@ -130,19 +130,15 @@ impl SessionsState { let total = self.filtered.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.list_state.select(Some(next)); } KeyCode::Enter => { if let Some(sel) = self.list_state.selected() { @@ -155,10 +151,8 @@ impl SessionsState { } } } - KeyCode::Char('d') => { - if self.list_state.selected().is_some() { - self.confirm_delete = true; - } + KeyCode::Char('d') if self.list_state.selected().is_some() => { + self.confirm_delete = true; } KeyCode::Char('/') => { self.search_mode = true; diff --git a/crates/openfang-cli/src/tui/screens/settings.rs b/crates/openfang-cli/src/tui/screens/settings.rs index b97e346059..167a204c3a 100644 --- a/crates/openfang-cli/src/tui/screens/settings.rs +++ b/crates/openfang-cli/src/tui/screens/settings.rs @@ -174,21 +174,17 @@ impl SettingsState { fn handle_providers(&mut self, key: KeyEvent) -> SettingsAction { let total = self.providers.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.provider_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.provider_list.select(Some(next)); - self.test_result = None; - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.provider_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.provider_list.select(Some(next)); + self.test_result = None; } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.provider_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.provider_list.select(Some(next)); - self.test_result = None; - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.provider_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.provider_list.select(Some(next)); + self.test_result = None; } KeyCode::Char('e') => { if let Some(sel) = self.provider_list.selected() { @@ -223,19 +219,15 @@ impl SettingsState { fn handle_models(&mut self, key: KeyEvent) -> SettingsAction { let total = self.models.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.model_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.model_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.model_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.model_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.model_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.model_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.model_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.model_list.select(Some(next)); } KeyCode::Char('r') => return SettingsAction::RefreshModels, _ => {} @@ -246,19 +238,15 @@ impl SettingsState { fn handle_tools(&mut self, key: KeyEvent) -> SettingsAction { let total = self.tools.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.tool_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.tool_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.tool_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.tool_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.tool_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.tool_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.tool_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.tool_list.select(Some(next)); } KeyCode::Char('r') => return SettingsAction::RefreshTools, _ => {} diff --git a/crates/openfang-cli/src/tui/screens/skills.rs b/crates/openfang-cli/src/tui/screens/skills.rs index 8832ed5f44..a0fae676fc 100644 --- a/crates/openfang-cli/src/tui/screens/skills.rs +++ b/crates/openfang-cli/src/tui/screens/skills.rs @@ -192,24 +192,18 @@ impl SkillsState { let total = self.installed.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.installed_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.installed_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.installed_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.installed_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.installed_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.installed_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.installed_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.installed_list.select(Some(next)); } - KeyCode::Char('u') => { - if self.installed_list.selected().is_some() { - self.confirm_uninstall = true; - } + KeyCode::Char('u') if self.installed_list.selected().is_some() => { + self.confirm_uninstall = true; } KeyCode::Char('c') => { if let Some(sel) = self.installed_list.selected() { @@ -256,19 +250,15 @@ impl SkillsState { let total = self.clawhub_results.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.clawhub_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.clawhub_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.clawhub_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.clawhub_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.clawhub_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.clawhub_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.clawhub_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.clawhub_list.select(Some(next)); } KeyCode::Char('i') => { if let Some(sel) = self.clawhub_list.selected() { @@ -296,19 +286,15 @@ impl SkillsState { fn handle_mcp(&mut self, key: KeyEvent) -> SkillsAction { let total = self.mcp_servers.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.mcp_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.mcp_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.mcp_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.mcp_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.mcp_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.mcp_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.mcp_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.mcp_list.select(Some(next)); } KeyCode::Char('r') => return SkillsAction::RefreshMcp, _ => {} diff --git a/crates/openfang-cli/src/tui/screens/templates.rs b/crates/openfang-cli/src/tui/screens/templates.rs index eae8faa723..193d3e464d 100644 --- a/crates/openfang-cli/src/tui/screens/templates.rs +++ b/crates/openfang-cli/src/tui/screens/templates.rs @@ -194,19 +194,15 @@ impl TemplatesState { let total = self.filtered.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.list_state.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.list_state.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.list_state.selected().unwrap_or(0); - let next = (i + 1) % total; - self.list_state.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.list_state.selected().unwrap_or(0); + let next = (i + 1) % total; + self.list_state.select(Some(next)); } KeyCode::Enter => { if let Some(sel) = self.list_state.selected() { diff --git a/crates/openfang-cli/src/tui/screens/triggers.rs b/crates/openfang-cli/src/tui/screens/triggers.rs index d55ddb6d55..8aeb093bd6 100644 --- a/crates/openfang-cli/src/tui/screens/triggers.rs +++ b/crates/openfang-cli/src/tui/screens/triggers.rs @@ -156,19 +156,15 @@ impl TriggerState { self.create_step -= 1; } } - KeyCode::Enter => { - if self.create_step < 5 { - self.create_step += 1; - } + KeyCode::Enter if self.create_step < 5 => { + self.create_step += 1; } KeyCode::Char(c) => match self.create_step { 0 => self.create_agent_id.push(c), 2 => self.create_pattern_param.push(c), 3 => self.create_prompt.push(c), - 4 => { - if c.is_ascii_digit() { - self.create_max_fires.push(c); - } + 4 if c.is_ascii_digit() => { + self.create_max_fires.push(c); } _ => {} }, diff --git a/crates/openfang-cli/src/tui/screens/usage.rs b/crates/openfang-cli/src/tui/screens/usage.rs index e0f829cf2c..525e315c2f 100644 --- a/crates/openfang-cli/src/tui/screens/usage.rs +++ b/crates/openfang-cli/src/tui/screens/usage.rs @@ -111,19 +111,15 @@ impl UsageState { UsageSub::ByModel => { let total = self.by_model.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.model_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.model_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.model_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.model_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.model_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.model_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.model_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.model_list.select(Some(next)); } KeyCode::Char('r') => return UsageAction::Refresh, _ => {} @@ -132,19 +128,15 @@ impl UsageState { UsageSub::ByAgent => { let total = self.by_agent.len(); match key.code { - KeyCode::Up | KeyCode::Char('k') => { - if total > 0 { - let i = self.agent_list.selected().unwrap_or(0); - let next = if i == 0 { total - 1 } else { i - 1 }; - self.agent_list.select(Some(next)); - } + KeyCode::Up | KeyCode::Char('k') if total > 0 => { + let i = self.agent_list.selected().unwrap_or(0); + let next = if i == 0 { total - 1 } else { i - 1 }; + self.agent_list.select(Some(next)); } - KeyCode::Down | KeyCode::Char('j') => { - if total > 0 { - let i = self.agent_list.selected().unwrap_or(0); - let next = (i + 1) % total; - self.agent_list.select(Some(next)); - } + KeyCode::Down | KeyCode::Char('j') if total > 0 => { + let i = self.agent_list.selected().unwrap_or(0); + let next = (i + 1) % total; + self.agent_list.select(Some(next)); } KeyCode::Char('r') => return UsageAction::Refresh, _ => {} diff --git a/crates/openfang-cli/src/tui/screens/wizard.rs b/crates/openfang-cli/src/tui/screens/wizard.rs index f15b8f8c8d..8b46638469 100644 --- a/crates/openfang-cli/src/tui/screens/wizard.rs +++ b/crates/openfang-cli/src/tui/screens/wizard.rs @@ -322,13 +322,11 @@ impl WizardState { KeyCode::Esc => { self.step = WizardStep::Provider; } - KeyCode::Enter => { - if !self.api_key_input.is_empty() { - if let Some(p) = self.selected_provider_info() { - self.model_input = p.default_model.to_string(); - } - self.step = WizardStep::Model; + KeyCode::Enter if !self.api_key_input.is_empty() => { + if let Some(p) = self.selected_provider_info() { + self.model_input = p.default_model.to_string(); } + self.step = WizardStep::Model; } KeyCode::Char(c) => { self.api_key_input.push(c); diff --git a/crates/openfang-kernel/src/kernel.rs b/crates/openfang-kernel/src/kernel.rs index 7a39e7bafb..41d486b4c8 100644 --- a/crates/openfang-kernel/src/kernel.rs +++ b/crates/openfang-kernel/src/kernel.rs @@ -3565,10 +3565,10 @@ impl OpenFangKernel { for req in &def.requires { match req.requirement_type { openfang_hands::RequirementType::ApiKey - | openfang_hands::RequirementType::EnvVar => { - if !req.check_value.is_empty() && !allowed_env.contains(&req.check_value) { - allowed_env.push(req.check_value.clone()); - } + | openfang_hands::RequirementType::EnvVar + if !req.check_value.is_empty() && !allowed_env.contains(&req.check_value) => + { + allowed_env.push(req.check_value.clone()); } _ => {} } @@ -3775,7 +3775,7 @@ impl OpenFangKernel { let mut bindings = self.bindings.lock().unwrap_or_else(|e| e.into_inner()); bindings.push(binding); // Sort by specificity descending - bindings.sort_by(|a, b| b.match_rule.specificity().cmp(&a.match_rule.specificity())); + bindings.sort_by_key(|b| std::cmp::Reverse(b.match_rule.specificity())); } /// Remove a binding by index, returns the removed binding if valid. diff --git a/crates/openfang-migrate/src/openclaw.rs b/crates/openfang-migrate/src/openclaw.rs index f79657899a..483e9e710b 100644 --- a/crates/openfang-migrate/src/openclaw.rs +++ b/crates/openfang-migrate/src/openclaw.rs @@ -896,10 +896,8 @@ fn derive_capabilities(tools: &[String]) -> AgentCapabilities { "shell_exec" => { caps.shell = vec!["*".to_string()]; } - "web_fetch" | "web_search" | "browser_navigate" => { - if caps.network.is_empty() { - caps.network = vec!["*".to_string()]; - } + "web_fetch" | "web_search" | "browser_navigate" if caps.network.is_empty() => { + caps.network = vec!["*".to_string()]; } "agent_send" | "agent_list" => { if caps.agent_message.is_empty() { diff --git a/crates/openfang-runtime/src/drivers/gemini.rs b/crates/openfang-runtime/src/drivers/gemini.rs index 3a1b9b964a..cac4c3a327 100644 --- a/crates/openfang-runtime/src/drivers/gemini.rs +++ b/crates/openfang-runtime/src/drivers/gemini.rs @@ -985,14 +985,14 @@ impl LlmDriver for GeminiDriver { thought_signature.clone(), )); } - GeminiPart::Thought { ref text, .. } => { - if !text.is_empty() { - let _ = tx - .send(StreamEvent::ThinkingDelta { - text: text.clone(), - }) - .await; - } + GeminiPart::Thought { ref text, .. } + if !text.is_empty() => + { + let _ = tx + .send(StreamEvent::ThinkingDelta { + text: text.clone(), + }) + .await; } _ => {} } diff --git a/crates/openfang-runtime/src/drivers/openai.rs b/crates/openfang-runtime/src/drivers/openai.rs index 2c3edc8cd2..967c26b9a8 100644 --- a/crates/openfang-runtime/src/drivers/openai.rs +++ b/crates/openfang-runtime/src/drivers/openai.rs @@ -308,16 +308,14 @@ impl LlmDriver for OpenAIDriver { // Convert messages for msg in &request.messages { match (&msg.role, &msg.content) { - (Role::System, MessageContent::Text(text)) => { - if request.system.is_none() { - oai_messages.push(OaiMessage { - role: "system".to_string(), - content: Some(OaiMessageContent::Text(text.clone())), - tool_calls: None, - tool_call_id: None, - reasoning_content: None, - }); - } + (Role::System, MessageContent::Text(text)) if request.system.is_none() => { + oai_messages.push(OaiMessage { + role: "system".to_string(), + content: Some(OaiMessageContent::Text(text.clone())), + tool_calls: None, + tool_call_id: None, + reasoning_content: None, + }); } (Role::User, MessageContent::Text(text)) => { oai_messages.push(OaiMessage { @@ -793,16 +791,14 @@ impl LlmDriver for OpenAIDriver { for msg in &request.messages { match (&msg.role, &msg.content) { - (Role::System, MessageContent::Text(text)) => { - if request.system.is_none() { - oai_messages.push(OaiMessage { - role: "system".to_string(), - content: Some(OaiMessageContent::Text(text.clone())), - tool_calls: None, - tool_call_id: None, - reasoning_content: None, - }); - } + (Role::System, MessageContent::Text(text)) if request.system.is_none() => { + oai_messages.push(OaiMessage { + role: "system".to_string(), + content: Some(OaiMessageContent::Text(text.clone())), + tool_calls: None, + tool_call_id: None, + reasoning_content: None, + }); } (Role::User, MessageContent::Text(text)) => { oai_messages.push(OaiMessage { diff --git a/crates/openfang-runtime/src/session_repair.rs b/crates/openfang-runtime/src/session_repair.rs index 1038be1ba4..666f0e832a 100644 --- a/crates/openfang-runtime/src/session_repair.rs +++ b/crates/openfang-runtime/src/session_repair.rs @@ -331,7 +331,7 @@ fn reorder_tool_results(messages: &mut Vec) -> usize { // Insert in reverse order so indices remain valid let mut sorted_insertions: Vec<(usize, Vec)> = insertions.into_iter().collect(); - sorted_insertions.sort_by(|a, b| b.0.cmp(&a.0)); + sorted_insertions.sort_by_key(|b| std::cmp::Reverse(b.0)); for (orig_assistant_idx, blocks) in sorted_insertions { if let Some(¤t_idx) = current_assistant_positions.get(&orig_assistant_idx) { @@ -433,7 +433,7 @@ fn insert_synthetic_results(messages: &mut Vec) -> usize { // Insert in reverse order so indices stay valid let mut sorted: Vec<(usize, Vec)> = grouped.into_iter().collect(); - sorted.sort_by(|a, b| b.0.cmp(&a.0)); + sorted.sort_by_key(|b| std::cmp::Reverse(b.0)); for (assistant_idx, blocks) in sorted { let insert_pos = assistant_idx + 1;