Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix: error handling in CLI tui (#1476)

MaojiaShengf9ff3e695295
diff --git a/crates/ov_cli/src/tui/app.rs b/crates/ov_cli/src/tui/app.rs
index 17b9ee191..719ffb66c 100644
--- a/crates/ov_cli/src/tui/app.rs
+++ b/crates/ov_cli/src/tui/app.rs
@@ -224,6 +224,12 @@ impl App {
self.error_message_time = Some(Instant::now());
}
+ /// Clear the error message immediately
+ pub fn clear_error_message(&mut self) {
+ self.error_message.clear();
+ self.error_message_time = None;
+ }
+
pub fn set_status_message(&mut self, message: String) {
if self.status_message_locked {
let message = format!("Error: Cannot set status message while locked");
@@ -253,6 +259,13 @@ impl App {
}
}
+ /// Clear confirmation and unlock status message in a single operation
+ /// This ensures we never leave status_message_locked stuck as true
+ pub fn clear_confirmation(&mut self) {
+ self.confirmation = None;
+ self.status_message_locked = false;
+ }
+
pub fn create_confirmation<F>(&mut self, message: String, on_confirmed: F)
where
F: for<'a> FnOnce(&'a mut App) -> Pin<Box<dyn Future<Output = ()> + 'a>> + 'static,
@@ -443,28 +456,30 @@ impl App {
self.set_status_message("Tree refreshed".to_string());
}
- pub async fn delete_selected_uri(&mut self) -> bool {
+ /// Delete the currently selected URI
+ /// Returns true if deletion was initiated (not whether it succeeded)
+ pub async fn delete_selected_uri(&mut self) {
if let Some(selected_uri) = self.tree.selected_uri() {
let is_dir = self.tree.selected_is_dir().unwrap_or(false);
- let deleted = self.delete_uri(selected_uri.to_string(), is_dir).await;
- deleted
+ self.delete_uri(selected_uri.to_string(), is_dir).await;
} else {
self.set_status_message("Nothing selected to delete".to_string());
- true
}
}
- pub async fn delete_uri(&mut self, selected_uri: String, is_dir: bool) -> bool {
-
+ /// Delete a specific URI
+ /// No return value - success/failure is communicated via status messages
+ pub async fn delete_uri(&mut self, selected_uri: String, is_dir: bool) {
if !self.tree.allow_deletion(&selected_uri) {
- return false;
+ self.set_error_message("Cannot delete root and scope directories".to_string());
+ return;
}
let client = self.client.clone();
-
+
// Collect expanded nodes before deletion
let expanded_nodes = self.collect_expanded_nodes();
-
+
// Determine target URI: next node if exists, otherwise previous node
let current_cursor = self.tree.cursor;
let target_uri = if current_cursor + 1 < self.tree.visible.len() {
@@ -485,15 +500,15 @@ impl App {
Some("/".to_string())
}
};
-
+
match client.rm(&selected_uri, is_dir).await {
Ok(_) => {
self.set_status_message(format!("Deleted: {}", selected_uri));
-
+
// Remove deleted node from expanded nodes
let mut expanded_nodes = expanded_nodes;
expanded_nodes.retain(|uri| uri != &selected_uri);
-
+
// Reload tree and restore state
if let Some(uri) = &target_uri {
self.reload_tree_and_restore_state(&client, &expanded_nodes, uri).await;
@@ -503,7 +518,5 @@ impl App {
self.set_status_message(format!("Delete failed: {}", e));
}
}
-
- true
}
}
diff --git a/crates/ov_cli/src/tui/event.rs b/crates/ov_cli/src/tui/event.rs
index 158f95cc4..f760fd980 100644
--- a/crates/ov_cli/src/tui/event.rs
+++ b/crates/ov_cli/src/tui/event.rs
@@ -3,12 +3,21 @@ use crossterm::event::{KeyCode, KeyEvent};
use super::app::{App, Panel};
pub async fn handle_key(app: &mut App, key: KeyEvent) {
- // Check for error message first - don't accept any input when error is shown
+ // Check for error message first - allow q to quit and Esc to clear
if !app.error_message.is_empty() {
+ match key.code {
+ KeyCode::Char('q') => {
+ app.should_quit = true;
+ }
+ KeyCode::Esc => {
+ app.clear_error_message();
+ }
+ _ => {}
+ }
return;
}
-
- // Check for confirmation first
+
+ // Check for confirmation first - allow q to quit, n/Esc to cancel
if app.confirmation.is_some() {
match key.code {
KeyCode::Char('y') => {
@@ -18,12 +27,16 @@ pub async fn handle_key(app: &mut App, key: KeyEvent) {
callback(app).await;
}
}
- KeyCode::Char('n') => {
+ KeyCode::Char('n') | KeyCode::Esc => {
// Cancel action
- app.confirmation.take();
- app.status_message_locked = false;
+ app.clear_confirmation();
app.set_status_message("Action cancelled".to_string());
}
+ KeyCode::Char('q') => {
+ // Allow quitting even during confirmation
+ app.clear_confirmation();
+ app.should_quit = true;
+ }
_ => {
// Ignore other keys during confirmation
}
@@ -75,20 +88,21 @@ async fn handle_tree_key(app: &mut App, key: KeyEvent) {
let selected_uri = selected_uri.to_string();
let is_dir = app.tree.selected_is_dir().unwrap_or(false);
+ // First check if deletion is allowed
+ if !app.tree.allow_deletion(&selected_uri) {
+ app.set_error_message("Cannot delete root and scope directories".to_string());
+ return;
+ }
+
// Create confirmation
- let message = format!("Delete {}? (y/n): {}",
- if is_dir { "directory" } else { "file" },
+ let message = format!("Delete {}? (y/n): {}",
+ if is_dir { "directory" } else { "file" },
selected_uri
);
app.create_confirmation(message, move |app| {
Box::pin(async move {
- let deleted = app.delete_selected_uri().await;
- if deleted {
- app.set_status_message(format!("Deleted {}", selected_uri));
- } else {
- app.set_error_message("Cannot delete root and scope directories".to_string());
- }
+ app.delete_selected_uri().await;
})
});
} else {
diff --git a/openviking/utils/search_filters.py b/openviking/utils/search_filters.py
index fc6bba822..677e0ce95 100644
--- a/openviking/utils/search_filters.py
+++ b/openviking/utils/search_filters.py
@@ -124,23 +124,26 @@ def _parse_time_value(value: str, now: datetime, *, is_upper_bound: bool) -> dat
return combined.replace(tzinfo=now.tzinfo)
return combined
- return parse_iso_datetime(value)
+ dt = parse_iso_datetime(value)
+ # Ensure it's in UTC for consistency
+ if dt.tzinfo is None:
+ dt = dt.replace(tzinfo=timezone.utc)
+ elif dt.tzinfo != timezone.utc:
+ dt = dt.astimezone(timezone.utc)
+ return dt
def _serialize_time_value(value: datetime) -> str:
- if value.tzinfo is None:
- return value.isoformat(timespec="milliseconds")
+ """Serialize datetime to ISO 8601 format, always in UTC."""
return format_iso8601(value)
def _comparison_datetime(value: datetime) -> datetime:
+ """Normalize datetime for comparison: always timezone-aware, in UTC."""
if value.tzinfo is not None:
- return value
-
- local_tz = datetime.now().astimezone().tzinfo
- if local_tz is None:
- raise ValueError("Could not determine local timezone for time filter comparison")
- return value.replace(tzinfo=local_tz)
+ return value.astimezone(timezone.utc)
+ # Naive datetime is treated as UTC for consistency with Context and time_utils
+ return value.replace(tzinfo=timezone.utc)
def _duration_from_unit(amount: int, unit: str) -> timedelta: