MCPcopy Create free account
hub / github.com/GCWing/BitFun / run

Method run

src/apps/cli/src/modes/chat.rs:274–811  ·  view source on GitHub ↗
(
        &mut self,
        existing_terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
    )

Source from the content-addressed store, hash-verified

272 }
273
274 pub fn run(
275 &mut self,
276 existing_terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
277 ) -> Result<ChatExitReason> {
278 tracing::info!("Starting Chat mode, Agent: {}", self.agent_type);
279 if let Some(ws) = &self.workspace {
280 tracing::info!("Workspace: {}", ws);
281 }
282
283 let mut terminal = match existing_terminal {
284 Some(t) => t,
285 None => init_terminal()?,
286 };
287
288 let appearance = resolve_appearance(&self.config.ui.theme);
289 let scheme = resolve_effective_color_scheme(&self.config.ui.color_scheme);
290 let base_is_light = appearance.is_light();
291 let base = match (base_is_light, scheme) {
292 (_, EffectiveColorScheme::Monochrome) => Theme::monochrome(),
293 (true, EffectiveColorScheme::Ansi16) => Theme::light_ansi16(),
294 (true, EffectiveColorScheme::Truecolor) => Theme::light(),
295 (false, EffectiveColorScheme::Ansi16) => Theme::dark_ansi16(),
296 (false, EffectiveColorScheme::Truecolor) => Theme::dark(),
297 };
298 let theme = self.resolve_configured_theme(base, appearance, scheme);
299 let mut chat_view = ChatView::new(theme);
300
301 // Create or restore core session
302 let rt_handle = tokio::runtime::Handle::current();
303
304 let (mut session_id, mut chat_state) = if let Some(ref restore_id) = self.restore_session_id
305 {
306 // Restore existing session
307 tracing::info!("Restoring session: {}", restore_id);
308 let agent = self.agent.clone();
309 let rid = restore_id.clone();
310 let agent_type = self.agent_type.clone();
311 let workspace = self.workspace.clone();
312
313 tokio::task::block_in_place(|| {
314 rt_handle.block_on(async {
315 // Restore session in core (loads metadata, messages, managers)
316 agent.restore_session(&rid).await?;
317
318 // Prefer session's stored workspace_path over startup workspace
319 let effective_workspace = agent
320 .coordinator()
321 .get_session_manager()
322 .get_session(&rid)
323 .and_then(|s| s.config.workspace_path.clone())
324 .or(workspace);
325
326 // Load historical messages for UI display
327 let messages = agent
328 .coordinator()
329 .get_messages(&rid)
330 .await
331 .unwrap_or_default();

Callers

nothing calls this directly

Calls 15

init_terminalFunction · 0.85
resolve_appearanceFunction · 0.85
agent_display_nameFunction · 0.85
pollFunction · 0.85
readFunction · 0.85
restore_terminalFunction · 0.85
is_lightMethod · 0.80
get_session_managerMethod · 0.80
ensure_sessionMethod · 0.80
trimMethod · 0.80

Tested by

no test coverage detected