pub mod agent_profile;
#[path = "latency/chat.rs"]
pub mod chat_latency;
pub mod context_health;
pub mod default_impl;
pub mod git_state;
pub mod history;
pub mod input_cursor;
pub mod input_edit;
pub mod message_cache;
pub mod model_picker;
pub mod model_picker_nav;
pub mod pending_tool;
pub mod profile_defs;
pub mod scroll;
pub mod session_nav;
pub mod settings_nav;
pub mod slash_commands;
pub mod slash_hints;
pub mod slash_suggest;
pub mod timing;
pub mod view_save;
pub mod worker_bridge;
#[cfg(test)]
mod tests;
pub use agent_profile::{SpawnedAgent, agent_profile};
pub use profile_defs::AgentProfile;
pub use slash_commands::SLASH_COMMANDS;
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;
use std::time::Instant;
use crate::session::{ImageAttachment, SessionSummary};
use crate::tui::models::{InputMode, ViewMode};
use crate::tui::{audit_view::AuditViewState, bus_log::BusLogState};
use crate::tui::{chat::message::ChatMessage, help::HelpScrollState};
use crate::tui::{ralph_view::RalphViewState, swarm_view::SwarmViewState};
use crate::tui::{symbol_search::SymbolSearchState, worker_bridge::IncomingTask};
pub use crate::session::SessionEvent;
#[derive(Default)]
pub struct App {
pub state: AppState,
}
pub struct AppState {
pub view_mode: ViewMode,
pub input_mode: InputMode,
pub messages: Vec<ChatMessage>,
pub input: String,
pub input_cursor: usize,
pub input_scroll: usize,
pub chat_scroll: usize,
pub chat_last_max_scroll: usize,
pub chat_auto_follow: bool,
pub tool_preview_scroll: usize,
pub tool_preview_last_max_scroll: usize,
pub protocol_selected: usize,
pub protocol_scroll: usize,
pub status: String,
pub processing: bool,
pub session_id: Option<String>,
pub sessions: Vec<SessionSummary>,
pub selected_session: usize,
pub session_filter: String,
pub cwd_display: String,
pub bus_log: BusLogState,
pub swarm: SwarmViewState,
pub audit: AuditViewState,
pub git: git_state::GitViewState,
pub ralph: RalphViewState,
pub symbol_search: SymbolSearchState,
pub slash_suggestions: Vec<String>,
pub selected_slash_suggestion: usize,
pub command_history: Vec<String>,
pub history_index: Option<usize>,
pub worker_id: Option<String>,
pub worker_name: Option<String>,
pub a2a_connected: bool,
pub peer_endpoint_ready: bool,
pub recent_tasks: Vec<String>,
pub worker_bridge_registered_agents: HashSet<String>,
pub worker_bridge_processing_state: Option<bool>,
pub worker_task_queue: VecDeque<IncomingTask>,
pub active_remote_task: Option<IncomingTask>,
pub help_scroll: HelpScrollState,
pub show_help: bool,
pub available_models: Vec<String>,
pub selected_model_index: usize,
pub model_picker_active: bool,
pub model_filter: String,
pub model_refresh_in_flight: bool,
pub model_refresh_rx:
Option<tokio::sync::mpsc::UnboundedReceiver<model_picker::ModelRefreshEvent>>,
pub model_picker_target_model: Option<String>,
pub streaming_text: String,
pub processing_started_at: Option<Instant>,
pub current_request_first_token_ms: Option<u64>,
pub current_request_last_token_ms: Option<u64>,
pub last_request_first_token_ms: Option<u64>,
pub last_request_last_token_ms: Option<u64>,
pub last_completion_model: Option<String>,
pub last_completion_latency_ms: Option<u64>,
pub last_completion_prompt_tokens: Option<usize>,
pub last_completion_output_tokens: Option<usize>,
pub context_used: Option<usize>,
pub context_budget: Option<usize>,
pub context_health: context_health::ContextHealthState,
pub last_tool_name: Option<String>,
pub last_tool_latency_ms: Option<u64>,
pub last_tool_success: Option<bool>,
pub pending_tool_name: Option<String>,
pub pending_tool_started_at: Option<Instant>,
pub chat_latency: chat_latency::ChatLatencyStats,
pub pending_images: Vec<ImageAttachment>,
pub pending_text_pastes: Vec<crate::tui::app::input::pasted_text::PendingTextPaste>,
pub auto_apply_edits: bool,
pub allow_network: bool,
pub slash_autocomplete: bool,
pub use_worktree: bool,
pub selected_settings_index: usize,
pub mcp_registry: Arc<crate::tui::app::mcp::TuiMcpRegistry>,
pub spawned_agents: HashMap<String, SpawnedAgent>,
pub active_spawned_agent: Option<String>,
pub streaming_agent_texts: HashMap<String, String>,
pub cached_message_lines: Vec<ratatui::text::Line<'static>>,
pub cached_messages_len: usize,
pub cached_max_width: usize,
pub cached_streaming_snapshot: Option<String>,
pub cached_processing: bool,
pub cached_frozen_len: usize,
pub watchdog_notification: Option<super::watchdog::WatchdogNotification>,
pub main_watchdog_root_prompt: Option<String>,
pub main_last_event_at: Option<Instant>,
pub main_watchdog_restart_count: u32,
pub main_inflight_prompt: Option<String>,
pub okr_repository: Option<Arc<crate::okr::OkrRepository>>,
pub pending_okr_approval: Option<super::okr_gate::PendingOkrApproval>,
pub pending_smart_switch_retry: Option<crate::tui::app::smart_switch::PendingSmartSwitchRetry>,
pub smart_switch_retry_count: u32,
pub smart_switch_attempted_models: Vec<String>,
pub chat_sync_rx:
Option<tokio::sync::mpsc::UnboundedReceiver<crate::tui::chat::sync::ChatSyncUiEvent>>,
pub chat_sync_status: Option<String>,
pub chat_sync_last_success: Option<String>,
pub chat_sync_last_error: Option<String>,
pub chat_sync_uploaded_bytes: u64,
pub chat_sync_uploaded_batches: u64,
pub autochat: super::autochat::state::AutochatState,
pub file_picker_dir: std::path::PathBuf,
pub file_picker_entries: Vec<crate::tui::app::file_picker::FilePickerEntry>,
pub file_picker_selected: usize,
pub file_picker_filter: String,
pub file_picker_active: bool,
pub workspace: crate::tui::models::WorkspaceSnapshot,
pub chat_layout_mode: crate::tui::ui::webview::layout_mode::ChatLayoutMode,
pub current_turn_cancel: Option<Arc<tokio::sync::Notify>>,
pub last_key_at: Option<Instant>,
pub recording_stop_flag: Option<Arc<std::sync::atomic::AtomicBool>>,
pub pending_voice_text: Option<Arc<std::sync::Mutex<Option<String>>>>,
pub saved_chat_scroll: usize,
pub saved_chat_auto_follow: bool,
pub saved_tool_preview_scroll: usize,
pub streaming_start: Option<Instant>,
pub streaming_chars: usize,
}