Problem
The TUI and REPL offline modes are currently broken or showing mock data instead of performing real searches:
Issues
-
Interactive TUI Offline Mode (main.rs:202-206)
- Has TODO comment
- Falls back to server mode (requires running server)
- Should use
TuiService for true standalone operation
-
REPL /search in Offline Mode (handler.rs:526-617)
- Shows hardcoded mock results
- Displays fake data like "Introduction to Terraphim"
- Doesn't actually search using
TuiService
-
REPL Autocomplete in Offline Mode (handler.rs:995+)
- Not implemented for offline mode
- Needs
TuiService.autocomplete() integration
-
Role/Config Commands Offline
- REPL offline mode doesn't properly handle role switching
- Config changes don't work without server
Current Behavior
# User expects offline mode to work
$ terraphim-tui repl
terraphim> /search "async"
📱 Offline mode - showing mock results # ← WRONG!
Introduction to Terraphim # ← FAKE DATA
Expected Behavior
$ terraphim-tui repl
terraphim> /search "async"
🔍 Searching for: 'async'
✅ Found 5 result(s)
- async programming patterns
- tokio runtime guide
- (real search results from TuiService)
Root Cause
REPL Handler doesn't use TuiService - only has Option<ApiClient>:
pub struct ReplHandler {
api_client: Option<ApiClient>, // ← Only this
current_role: String,
command_registry: Option<CommandRegistry>,
}
Solution
1. Add TuiService to ReplHandler
pub struct ReplHandler {
api_client: Option<ApiClient>,
tui_service: Option<TuiService>, // ← ADD THIS
current_role: String,
command_registry: Option<CommandRegistry>,
}
2. Initialize TuiService in Offline Mode
pub async fn run_repl_offline_mode() -> Result<()> {
let mut handler = ReplHandler::new_offline();
handler.initialize_offline_service().await?; // ← Initialize TuiService
handler.run().await
}
impl ReplHandler {
pub async fn initialize_offline_service(&mut self) -> Result<()> {
self.tui_service = Some(TuiService::new().await?);
// Get actual role from service
if let Some(service) = &self.tui_service {
self.current_role = service.get_selected_role().await.to_string();
}
Ok(())
}
}
3. Fix handle_search for Offline
Replace mock data section (line 526-617) with:
if self.api_client.is_none() {
// Offline mode - use TuiService
if let Some(service) = &self.tui_service {
let role_name = role.as_ref()
.map(|r| RoleName::new(r))
.unwrap_or_else(|| RoleName::new(&self.current_role));
let results = service.search_with_role(&query, &role_name, limit).await?;
// Display REAL results (not mock)
// ... format and display table
} else {
println!("⚠️ Offline service not initialized. Run with --server flag.");
}
}
4. Fix handle_autocomplete
if self.api_client.is_none() {
// Offline mode - use TuiService
if let Some(service) = &self.tui_service {
let role_name = RoleName::new(&self.current_role);
let results = service.autocomplete(&role_name, &query, limit).await?;
// Display autocomplete results
for (i, result) in results.iter().enumerate() {
println!(" {}. {}", i + 1, result.text);
}
}
}
5. Fix Interactive TUI Offline Mode
Update main.rs:202-206:
fn run_tui_offline_mode(transparent: bool) -> Result<()> {
let rt = Runtime::new()?;
let service = rt.block_on(async { TuiService::new().await })?;
run_tui_with_service(transparent, service, rt)
}
Create new ui_loop_offline() that uses TuiService instead of ApiClient.
Implementation Checklist
Affected Files
crates/terraphim_tui/src/repl/handler.rs - Main REPL logic
crates/terraphim_tui/src/main.rs - Interactive TUI offline mode
docs/tui-usage.md - Documentation
- Tests: Add offline mode integration tests
Benefits
✅ True offline operation without requiring server
✅ Real search results from local haystacks
✅ Real autocomplete from thesaurus
✅ Consistent behavior between offline/online modes
✅ Better user experience for local-only usage
Problem
The TUI and REPL offline modes are currently broken or showing mock data instead of performing real searches:
Issues
Interactive TUI Offline Mode (
main.rs:202-206)TuiServicefor true standalone operationREPL /search in Offline Mode (
handler.rs:526-617)TuiServiceREPL Autocomplete in Offline Mode (
handler.rs:995+)TuiService.autocomplete()integrationRole/Config Commands Offline
Current Behavior
Expected Behavior
Root Cause
REPL Handler doesn't use
TuiService- only hasOption<ApiClient>:Solution
1. Add TuiService to ReplHandler
2. Initialize TuiService in Offline Mode
3. Fix handle_search for Offline
Replace mock data section (line 526-617) with:
4. Fix handle_autocomplete
5. Fix Interactive TUI Offline Mode
Update
main.rs:202-206:Create new
ui_loop_offline()that usesTuiServiceinstead ofApiClient.Implementation Checklist
tui_service: Option<TuiService>to ReplHandler structinitialize_offline_service()methodrun_repl_offline_mode()to initialize TuiServicehandle_search()offline branch to use TuiServicehandle_autocomplete()offline branch to use TuiServicehandle_role()offline branchhandle_config()offline branchrun_tui_offline_mode()in main.rsui_loop_offline()or refactor to accept either ApiClient or TuiServiceAffected Files
crates/terraphim_tui/src/repl/handler.rs- Main REPL logiccrates/terraphim_tui/src/main.rs- Interactive TUI offline modedocs/tui-usage.md- DocumentationBenefits
✅ True offline operation without requiring server
✅ Real search results from local haystacks
✅ Real autocomplete from thesaurus
✅ Consistent behavior between offline/online modes
✅ Better user experience for local-only usage