style: format seluruh workspace dengan cargo fmt

Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya
lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
asepharyana
2026-08-27 22:10:28 +07:00
parent 884b19ccb5
commit 7b0b53671f
127 changed files with 1271 additions and 1156 deletions
+41 -46
View File
@@ -15,7 +15,6 @@
//! 4. After each request, `send_daemon_update` pushes a full state
//! snapshot back to the client
use anyhow::Result;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use tracing::info;
@@ -27,9 +26,7 @@ use zesdex_infrastructure::ipc::protocol::{
use zesdex_infrastructure::utils::CastOr;
use crate::key_code::key_action_to_code;
use crate::state::{
AppStateRest, AutocompleteKind, ChatMessageDisplay, Overlay, RoleWrapper,
};
use crate::state::{AppStateRest, AutocompleteKind, ChatMessageDisplay, Overlay, RoleWrapper};
// ---------------------------------------------------------------------------
// Action enum
@@ -80,30 +77,17 @@ pub enum Action {
/// Periodic timer tick — drains queued events and runs side jobs.
Tick,
/// Accept a lesson by name.
LessonAccept {
name: String,
},
LessonAccept { name: String },
/// Reject a lesson by name.
LessonReject {
name: String,
},
LessonReject { name: String },
/// Delete a previously stored lesson by name.
LessonDelete {
name: String,
},
LessonDelete { name: String },
/// Start the OAuth device-code login flow for a named provider.
StartOAuth {
provider: String,
},
StartOAuth { provider: String },
/// Open the inline file editor for `path`.
OpenEditor {
path: String,
},
OpenEditor { path: String },
/// Register a new MCP server by name and shell command.
McpAdd {
name: String,
command: String,
},
McpAdd { name: String, command: String },
/// Open the model-picker overlay.
ModelList,
/// Set the abort flag on the currently running turn.
@@ -149,9 +133,10 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
Action::CloseOverlay => handle_close_overlay(state),
// ── System / info ─────────────────────────────────────────────
Action::SystemNote { kind: _kind, message } => {
handle_system_note(state, message)
}
Action::SystemNote {
kind: _kind,
message,
} => handle_system_note(state, message),
Action::ModelList => handle_model_list(state),
Action::AbortTurn => handle_abort_turn(state),
Action::Compact => handle_compact(state),
@@ -228,7 +213,10 @@ fn handle_tick(state: &mut AppStateRest) {
TurnEvent::Error(e) => {
state.toast_error(e);
}
TurnEvent::Usage { tokens_in, tokens_out } => {
TurnEvent::Usage {
tokens_in,
tokens_out,
} => {
if let Some(ref mut rt) = state.session_runtime {
rt.usage.tokens_in = rt.usage.tokens_in.saturating_add(tokens_in);
rt.usage.tokens_out = rt.usage.tokens_out.saturating_add(tokens_out);
@@ -458,7 +446,9 @@ fn handle_model_list(state: &mut AppStateRest) {
}
fn handle_abort_turn(state: &mut AppStateRest) {
state.abort_flag.store(true, std::sync::atomic::Ordering::SeqCst);
state
.abort_flag
.store(true, std::sync::atomic::Ordering::SeqCst);
if let Ok(mut in_flight) = state.turn_in_flight.lock() {
*in_flight = false;
}
@@ -469,15 +459,26 @@ fn handle_compact(state: &mut AppStateRest) {
tracing::info!("compacting conversation with AI summarization");
let provider_name = &state.settings.provider;
let provider_cfg = state.app_config.providers.get(provider_name).cloned();
let api_key = state.settings.api_keys.get(provider_name).cloned().unwrap_or_default();
let api_key = state
.settings
.api_keys
.get(provider_name)
.cloned()
.unwrap_or_default();
let model = state.settings.model.clone();
let api_base = provider_cfg.map(|cfg| cfg.api_base.clone());
let client = zesdex_infrastructure::llm::provider::LlmClient::new(api_key, model, api_base);
if let Some(ref mut rt) = state.session_runtime {
let tokio_rt = tokio::runtime::Runtime::new().expect("create tokio runtime for AI compaction");
if let Ok(()) = tokio_rt.block_on(zesdex_application::agent::turn_service::compact_messages_with_ai(&mut rt.messages, &client)) {
let tokio_rt =
tokio::runtime::Runtime::new().expect("create tokio runtime for AI compaction");
if let Ok(()) = tokio_rt.block_on(
zesdex_application::agent::turn_service::compact_messages_with_ai(
&mut rt.messages,
&client,
),
) {
let msg_count = rt.messages.len();
state.push_transcript(ChatMessageDisplay::new(
RoleWrapper::System,
@@ -619,8 +620,8 @@ pub fn handle_key(key: KeyEvent, state: &mut AppStateRest) -> Vec<Action> {
state.input.open_autocomplete();
state.dirty = true;
} else {
state.input.autocomplete_idx =
(state.input.autocomplete_idx + 1) % state.input.autocomplete_candidates.len().max(1);
state.input.autocomplete_idx = (state.input.autocomplete_idx + 1)
% state.input.autocomplete_candidates.len().max(1);
state.dirty = true;
}
vec![]
@@ -638,11 +639,12 @@ pub fn handle_key(key: KeyEvent, state: &mut AppStateRest) -> Vec<Action> {
} else if state.input.autocomplete_visible {
// Select the current autocomplete candidate
if !state.input.autocomplete_candidates.is_empty() {
let idx = state.input.autocomplete_idx
let idx = state
.input
.autocomplete_idx
.min(state.input.autocomplete_candidates.len().saturating_sub(1));
if state.input.autocomplete_kind == AutocompleteKind::Command {
state.input.buffer =
state.input.autocomplete_candidates[idx].clone();
state.input.buffer = state.input.autocomplete_candidates[idx].clone();
state.input.cursor = state.input.buffer.len();
}
state.input.close_autocomplete();
@@ -778,10 +780,7 @@ pub fn send_daemon_update(conn: &mut Connection, state: &AppStateRest) -> Result
/// Handle an incoming client connection for the daemon.
///
/// Flow: loop reading requests, modifying state, and sending updates back.
pub fn handle_daemon_client(
mut conn: Connection,
state: &mut AppStateRest,
) -> Result<()> {
pub fn handle_daemon_client(mut conn: Connection, state: &mut AppStateRest) -> Result<()> {
tracing::debug!("handling daemon client connection");
let mut running = true;
while running {
@@ -807,8 +806,7 @@ pub fn handle_daemon_client(
if shift {
modifiers |= KeyModifiers::SHIFT;
}
let key_event =
KeyEvent::new(key_action_to_code(&key), modifiers);
let key_event = KeyEvent::new(key_action_to_code(&key), modifiers);
let actions = handle_key(key_event, state);
for action in actions {
apply_action(state, action);
@@ -817,10 +815,7 @@ pub fn handle_daemon_client(
}
ClientRequest::Submit(text) => {
state.input.buffer = text;
let enter_event = KeyEvent::new(
KeyCode::Enter,
KeyModifiers::NONE,
);
let enter_event = KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE);
let actions = handle_key(enter_event, state);
for action in actions {
apply_action(state, action);