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
+5 -11
View File
@@ -15,7 +15,6 @@
use std::io::{self};
use anyhow::Result;
use zesdex_domain::SettingsRepository;
use crossterm::execute;
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
@@ -24,6 +23,7 @@ use ratatui::backend::CrosstermBackend;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
use ratatui::Terminal;
use zesdex_domain::SettingsRepository;
use zesdex_infrastructure::ipc::client::IpcClient;
use zesdex_infrastructure::ipc::protocol::{ClientRequest, DaemonFrame, StatePayload};
use zesdex_infrastructure::Toast;
@@ -197,7 +197,7 @@ fn draw(frame: &mut ratatui::Frame, state: &AppStateRest) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(1), // main content (transcript + toasts)
Constraint::Min(1), // main content (transcript + toasts)
Constraint::Length(3), // input line
])
.split(area);
@@ -245,9 +245,7 @@ fn draw(frame: &mut ratatui::Frame, state: &AppStateRest) {
let content = content_lines.join("\n");
let main_block = Block::default()
.title(title)
.borders(Borders::TOP);
let main_block = Block::default().title(title).borders(Borders::TOP);
let paragraph = Paragraph::new(content)
.block(main_block)
.wrap(Wrap { trim: false })
@@ -261,8 +259,7 @@ fn draw(frame: &mut ratatui::Frame, state: &AppStateRest) {
} else {
state.input.buffer.clone()
};
let input_paragraph = Paragraph::new(input_display)
.block(input_block);
let input_paragraph = Paragraph::new(input_display).block(input_block);
frame.render_widget(input_paragraph, chunks[1]);
// Set cursor position for the input line.
@@ -347,10 +344,7 @@ pub fn run_attach(session_id: &str) -> Result<()> {
client.send(&ClientRequest::Tick)?;
}
handle_daemon_frame(
&mut client_state,
client.receive::<DaemonFrame>()?,
);
handle_daemon_frame(&mut client_state, client.receive::<DaemonFrame>()?);
terminal.draw(|f| {
draw(f, &client_state);
+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);
+7 -12
View File
@@ -16,19 +16,19 @@ use anyhow::Result;
use tokio::sync::RwLock;
use zesdex_domain::cms::EditLog;
use zesdex_domain::Session;
use zesdex_domain::Settings;
use zesdex_domain::AppConfigRepository;
use zesdex_domain::EditLogRepository;
use zesdex_domain::Session;
use zesdex_domain::SessionLockRepository;
use zesdex_domain::SessionRepository;
use zesdex_domain::Settings;
use zesdex_domain::SettingsRepository;
use zesdex_infrastructure::lsp::manager::LspManager;
use zesdex_infrastructure::mcp::manager::McpManager;
use zesdex_infrastructure::persistence::FileSystemSessionLockRepository;
use zesdex_infrastructure::persistence::JsonAppConfigRepository;
use zesdex_infrastructure::persistence::JsonlEditLogRepository;
use zesdex_infrastructure::persistence::JsonSettingsRepository;
use zesdex_infrastructure::persistence::JsonlEditLogRepository;
use zesdex_infrastructure::AppConfig;
use zesdex_infrastructure::DirCache;
use zesdex_infrastructure::MentionIndex;
@@ -375,9 +375,7 @@ pub struct WorkflowEngine {
impl WorkflowEngine {
/// Create an empty workflow engine.
pub fn new() -> Self {
Self {
agents: Vec::new(),
}
Self { agents: Vec::new() }
}
}
@@ -487,8 +485,7 @@ impl AppStateRest {
session_dir: &std::path::Path,
memory_dir: PathBuf,
) -> Self {
let store_base_dir =
zesdex_infrastructure::Store::new().base_dir;
let store_base_dir = zesdex_infrastructure::Store::new().base_dir;
let settings = JsonSettingsRepository::new()
.load(&store_base_dir)
.unwrap_or_default();
@@ -705,8 +702,7 @@ impl AppStateRest {
/// Persist the current settings to the store and swallow any error.
pub fn save_settings(&self) {
let _ = JsonSettingsRepository::new()
.save(&self.store_base_dir(), &self.settings);
let _ = JsonSettingsRepository::new().save(&self.store_base_dir(), &self.settings);
}
}
@@ -807,8 +803,7 @@ pub fn create_session() -> Result<(
let workspace_roots = vec![std::env::current_dir()?];
let mut state = AppStateRest::new(workspace_roots, &session_dir, store.memory_dir.clone());
state.spawn_mention_index_build();
let session_repo =
zesdex_infrastructure::persistence::FileSystemSessionRepository::new();
let session_repo = zesdex_infrastructure::persistence::FileSystemSessionRepository::new();
state.sessions = session_repo
.list_sessions(&store.base_dir)
.unwrap_or_default();