Skip to content

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

feat: ov --progress (#1872)

MaojiaSheng3ed866924894
diff --git a/Cargo.lock b/Cargo.lock
index 3dd5e4775..050bafef1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -975,6 +975,18 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "console"
+version = "0.16.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87"
+dependencies = [
+ "encode_unicode",
+ "libc",
+ "unicode-width 0.2.0",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "const-oid"
version = "0.9.6"
@@ -1475,6 +1487,12 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "encode_unicode"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
+
[[package]]
name = "endian-type"
version = "0.1.2"
@@ -2236,6 +2254,19 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "indicatif"
+version = "0.18.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25470f23803092da7d239834776d653104d551bc4d7eacaf31e6837854b8e9eb"
+dependencies = [
+ "console",
+ "portable-atomic",
+ "unicode-width 0.2.0",
+ "unit-prefix",
+ "web-time",
+]
+
[[package]]
name = "indoc"
version = "2.0.7"
@@ -2713,6 +2744,7 @@ name = "ov_cli"
version = "0.2.6"
dependencies = [
"anyhow",
+ "bytes",
"clap",
"colored",
"crossterm 0.28.1",
@@ -2720,6 +2752,7 @@ dependencies = [
"futures",
"getrandom 0.2.17",
"hex",
+ "indicatif",
"machine-uid",
"mime_guess",
"ratatui",
@@ -4588,6 +4621,12 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
+[[package]]
+name = "unit-prefix"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3"
+
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
diff --git a/crates/ov_cli/Cargo.toml b/crates/ov_cli/Cargo.toml
index 8a436ec43..5b47e0442 100644
--- a/crates/ov_cli/Cargo.toml
+++ b/crates/ov_cli/Cargo.toml
@@ -36,3 +36,5 @@ machine-uid = "0.5"
termimad = "0.34"
hex = "0.4"
getrandom = "0.2"
+indicatif = "0.18"
+bytes = "1.0"
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rs
index 8412804c6..6f26d40cc 100644
--- a/crates/ov_cli/src/client.rs
+++ b/crates/ov_cli/src/client.rs
@@ -8,6 +8,8 @@ use tempfile::{Builder, NamedTempFile};
use zip::CompressionMethod;
use zip::write::FileOptions;
+use indicatif::{ProgressBar, ProgressStyle};
+
use crate::error::{Error, Result};
fn api_error_from_envelope(json: &Value, status: StatusCode) -> String {
@@ -648,6 +650,8 @@ impl HttpClient {
exclude: Option<String>,
directly_upload_media: bool,
watch_interval: f64,
+ show_progress: bool,
+ verbose: bool,
) -> Result<serde_json::Value> {
let path_obj = Path::new(path);
@@ -657,8 +661,16 @@ impl HttpClient {
.file_name()
.and_then(|n| n.to_str())
.map(|s| s.to_string());
- let zip_file = self.zip_directory(path_obj)?;
- let temp_file_id = self.upload_temp_file(zip_file.path()).await?;
+ let zip_file = if show_progress {
+ self.zip_directory_with_progress(path_obj, verbose)?
+ } else {
+ self.zip_directory(path_obj)?
+ };
+ let temp_file_id = if show_progress {
+ self.upload_temp_file_with_progress(zip_file.path(), verbose).await?
+ } else {
+ self.upload_temp_file(zip_file.path()).await?
+ };
let body = serde_json::json!({
"temp_file_id": temp_file_id,
@@ -683,7 +695,11 @@ impl HttpClient {
.file_name()
.and_then(|n| n.to_str())
.map(|s| s.to_string());
- let temp_file_id = self.upload_temp_file(path_obj).await?;
+ let temp_file_id = if show_progress {
+ self.upload_temp_file_with_progress(path_obj, verbose).await?
+ } else {
+ self.upload_temp_file(path_obj).await?
+ };
let body = serde_json::json!({
"temp_file_id": temp_file_id,
@@ -743,6 +759,161 @@ impl HttpClient {
}
}
+ /// Zip a directory to a temporary file with progress display
+ fn zip_directory_with_progress(&self, dir_path: &Path, verbose: bool) -> Result<NamedTempFile> {
+ if !dir_path.is_dir() {
+ return Err(Error::Network(format!(
+ "Path {} is not a directory",
+ dir_path.display()
+ )));
+ }
+
+ let temp_file = Builder::new().suffix(".zip").tempfile()?;
+ let file = File::create(temp_file.path())?;
+ let mut zip = zip::ZipWriter::new(file);
+ let options: FileOptions<'_, ()> =
+ FileOptions::default().compression_method(CompressionMethod::Deflated);
+
+ // First, calculate total size and file count
+ let mut total_size = 0u64;
+ let mut total_files = 0u64;
+ let walkdir = walkdir::WalkDir::new(dir_path);
+ for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
+ let path = entry.path();
+ if path.is_file() {
+ if let Ok(meta) = std::fs::metadata(path) {
+ total_size += meta.len();
+ total_files += 1;
+ }
+ }
+ }
+
+ // Now create progress bar and zip
+ let pb = if total_size > 0 {
+ let pb = ProgressBar::new(total_size);
+ pb.set_style(
+ ProgressStyle::default_bar()
+ .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta}) {msg}")
+ .unwrap_or_else(|_| ProgressStyle::default_bar())
+ .progress_chars("#>-"),
+ );
+ pb.set_message(format!("Compressing {} files", total_files));
+ Some(pb)
+ } else {
+ let pb = ProgressBar::new_spinner();
+ pb.set_message("Compressing files...");
+ Some(pb)
+ };
+
+ let walkdir = walkdir::WalkDir::new(dir_path);
+ for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
+ let path = entry.path();
+ if path.is_file() {
+ let name = path.strip_prefix(dir_path).unwrap_or(path);
+ let name_str = name.to_str().ok_or_else(|| {
+ Error::InvalidPath(format!("Non-UTF-8 path: {}", name.to_string_lossy()))
+ })?;
+ if verbose {
+ eprintln!(" Adding: {}", name_str);
+ }
+ zip.start_file(name_str, options)?;
+ let mut file = File::open(path)?;
+ let file_size = std::io::copy(&mut file, &mut zip)?;
+
+ if let Some(pb) = &pb {
+ if pb.length().is_some() {
+ pb.inc(file_size);
+ }
+ }
+ }
+ }
+
+ zip.finish()?;
+
+ let zip_size = std::fs::metadata(temp_file.path())?.len();
+ let zip_size_mb = zip_size as f64 / 1024.0 / 1024.0;
+ let original_size_mb = if total_size > 0 {
+ total_size as f64 / 1024.0 / 1024.0
+ } else {
+ 0.0
+ };
+
+ if let Some(pb) = pb {
+ if total_size > 0 {
+ pb.finish_with_message(format!("Compression complete: {:.2} MiB → {:.2} MiB", original_size_mb, zip_size_mb));
+ } else {
+ pb.finish_with_message(format!("Compression complete: {:.2} MiB", zip_size_mb));
+ }
+ }
+
+ Ok(temp_file)
+ }
+
+ /// Upload a temporary file with progress display
+ async fn upload_temp_file_with_progress(
+ &self,
+ file_path: &Path,
+ verbose: bool,
+ ) -> Result<String> {
+ use indicatif::ProgressBar;
+
+ let url = format!("{}/api/v1/resources/temp_upload", self.base_url);
+ let file_name = file_path
+ .file_name()
+ .and_then(|n| n.to_str())
+ .unwrap_or("temp_upload.zip");
+
+ // Read file content
+ let file_content = tokio::fs::read(file_path).await?;
+ let file_size = file_content.len() as u64;
+
+ if verbose {
+ eprintln!("Uploading: {} ({:.2} MB)", file_name, file_size as f64 / 1024.0 / 1024.0);
+ }
+
+ // Create progress bar (spinner style)
+ let pb = ProgressBar::new_spinner();
+ pb.set_message(format!("Uploading {} ({:.2} MB)...", file_name, file_size as f64 / 1024.0 / 1024.0));
+ pb.enable_steady_tick(std::time::Duration::from_millis(100));
+
+ // Create multipart form
+ let part = reqwest::multipart::Part::bytes(file_content)
+ .file_name(file_name.to_string());
+
+ let part = part
+ .mime_str("application/octet-stream")
+ .map_err(|e| Error::Network(format!("Failed to set mime type: {}", e)))?;
+
+ let form = reqwest::multipart::Form::new().part("file", part);
+
+ let mut headers = self.build_headers();
+ headers.remove(reqwest::header::CONTENT_TYPE);
+
+ // Use a separate HTTP client with a long timeout for large file uploads
+ let long_timeout_client = reqwest::Client::builder()
+ .connect_timeout(std::time::Duration::from_secs(30))
+ .timeout(std::time::Duration::from_secs(1800))
+ .build()
+ .map_err(|e| Error::Network(format!("Failed to build long-timeout HTTP client: {}", e)))?;
+
+ let response = long_timeout_client
+ .post(&url)
+ .headers(headers)
+ .multipart(form)
+ .send()
+ .await
+ .map_err(|e| Error::Network(format!("File upload failed: {}", e)))?;
+
+ pb.finish_with_message("Upload complete");
+
+ let result: Value = self.handle_response(response).await?;
+ result
+ .get("temp_file_id")
+ .and_then(|v| v.as_str())
+ .map(|s| s.to_string())
+ .ok_or_else(|| Error::Parse("Missing temp_file_id in response".to_string()))
+ }
+
pub async fn add_skill(
&self,
data: &str,
diff --git a/crates/ov_cli/src/commands/resources.rs b/crates/ov_cli/src/commands/resources.rs
index 3bb8a38e9..5b4859b70 100644
--- a/crates/ov_cli/src/commands/resources.rs
+++ b/crates/ov_cli/src/commands/resources.rs
@@ -19,6 +19,8 @@ pub async fn add_resource(
watch_interval: f64,
format: OutputFormat,
compact: bool,
+ show_progress: bool,
+ verbose: bool,
) -> Result<()> {
let result = client
.add_resource(
@@ -35,6 +37,8 @@ pub async fn add_resource(
exclude,
directly_upload_media,
watch_interval,
+ show_progress,
+ verbose,
)
.await?;
diff --git a/crates/ov_cli/src/config.rs b/crates/ov_cli/src/config.rs
index 917a91578..6efc6818b 100644
--- a/crates/ov_cli/src/config.rs
+++ b/crates/ov_cli/src/config.rs
@@ -39,6 +39,10 @@ pub struct Config {
pub output: String,
#[serde(default = "default_echo_command")]
pub echo_command: bool,
+ #[serde(default = "default_show_progress")]
+ pub show_progress: bool,
+ #[serde(default = "default_verbose")]
+ pub verbose: bool,
#[serde(default)]
pub upload: UploadConfig,
#[serde(default, alias = "extra_header")]
@@ -61,6 +65,14 @@ fn default_echo_command() -> bool {
true
}
+fn default_show_progress() -> bool {
+ false
+}
+
+fn default_verbose() -> bool {
+ false
+}
+
impl Default for Config {
fn default() -> Self {
Self {
@@ -73,6 +85,8 @@ impl Default for Config {
timeout: 60.0,
output: "table".to_string(),
echo_command: true,
+ show_progress: false,
+ verbose: false,
upload: UploadConfig::default(),
extra_headers: None,
}
diff --git a/crates/ov_cli/src/handlers.rs b/crates/ov_cli/src/handlers.rs
index a4f247c86..afada572a 100644
--- a/crates/ov_cli/src/handlers.rs
+++ b/crates/ov_cli/src/handlers.rs
@@ -101,6 +101,8 @@ pub async fn handle_add_resource(
watch_interval,
ctx.output_format,
ctx.compact,
+ ctx.should_show_progress(),
+ ctx.is_verbose(),
)
.await
}
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rs
index 9e411c86d..f86763a7c 100644
--- a/crates/ov_cli/src/main.rs
+++ b/crates/ov_cli/src/main.rs
@@ -20,6 +20,10 @@ pub struct CliContext {
pub output_format: OutputFormat,
pub compact: bool,
pub sudo: bool,
+ /// Whether to show upload progress (override config)
+ pub show_progress: Option<bool>,
+ /// Whether to enable verbose output (override config)
+ pub verbose: Option<bool>,
}
impl CliContext {
@@ -30,6 +34,8 @@ impl CliContext {
user: Option<String>,
agent_id: Option<String>,
sudo: bool,
+ show_progress: Option<bool>,
+ verbose: Option<bool>,
) -> Result<Self> {
let config = Config::load()?;
Ok(Self::from_config(
@@ -40,6 +46,8 @@ impl CliContext {
user,
agent_id,
sudo,
+ show_progress,
+ verbose,
))
}
@@ -51,6 +59,8 @@ impl CliContext {
user: Option<String>,
agent_id: Option<String>,
sudo: bool,
+ show_progress: Option<bool>,
+ verbose: Option<bool>,
) -> Self {
if account.is_some() {
config.account = account;
@@ -66,9 +76,21 @@ impl CliContext {
output_format,
compact,
sudo,
+ show_progress,
+ verbose,
}
}
+ /// Check if progress should be shown
+ pub fn should_show_progress(&self) -> bool {
+ self.show_progress.unwrap_or(self.config.show_progress)
+ }
+
+ /// Check if verbose output is enabled
+ pub fn is_verbose(&self) -> bool {
+ self.verbose.unwrap_or(self.config.verbose)
+ }
+
pub fn get_client(&self) -> client::HttpClient {
self.get_client_with_timeout(None)
}
@@ -121,6 +143,18 @@ struct Cli {
#[arg(long, global = true)]
sudo: bool,
+ /// Show upload progress (overrides config file)
+ #[arg(long, global = true)]
+ progress: bool,
+
+ /// Disable upload progress (overrides config file)
+ #[arg(long = "no-progress", global = true, conflicts_with = "progress")]
+ no_progress: bool,
+
+ /// Enable verbose output (overrides config file)
+ #[arg(short, long, global = true)]
+ verbose: bool,
+
#[command(subcommand)]
command: Commands,
}
@@ -794,7 +828,7 @@ fn find_command_index(args: &[OsString]) -> Option<usize> {
"--output" | "-o" | "--compact" | "--account" | "--user" | "--agent-id" => {
i += 2;
}
- "--sudo" => {
+ "--sudo" | "--progress" | "--no-progress" | "--verbose" | "-v" => {
i += 1;
}
_ if token.starts_with('-') => {
@@ -904,6 +938,17 @@ async fn main() {
let output_format = cli.output;
let compact = cli.compact;
+ // Determine show_progress override:
+ let show_progress = if cli.progress {
+ Some(true)
+ } else if cli.no_progress {
+ Some(false)
+ } else {
+ None
+ };
+ // Determine verbose override:
+ let verbose = if cli.verbose { Some(true) } else { None };
+
let ctx = match CliContext::new(
output_format,
compact,
@@ -911,6 +956,8 @@ async fn main() {
cli.user.clone(),
cli.agent_id.clone(),
cli.sudo,
+ show_progress,
+ verbose,
) {
Ok(ctx) => ctx,
Err(e) => {
@@ -1192,6 +1239,8 @@ mod tests {
timeout: 60.0,
output: "table".to_string(),
echo_command: true,
+ show_progress: false,
+ verbose: false,
upload: Default::default(),
extra_headers: None,
};
@@ -1204,6 +1253,8 @@ mod tests {
Some("from-cli-user".to_string()),
Some("from-cli-agent".to_string()),
false,
+ None,
+ None,
);
assert_eq!(ctx.config.account.as_deref(), Some("from-cli-account"));
@@ -1223,6 +1274,8 @@ mod tests {
timeout: 60.0,
output: "table".to_string(),
echo_command: true,
+ show_progress: false,
+ verbose: false,
upload: Default::default(),
extra_headers: None,
};
@@ -1236,6 +1289,8 @@ mod tests {
None,
None,
false,
+ None,
+ None,
);
let client = ctx.get_client();
assert_eq!(client.api_key(), Some("user-key"));
@@ -1249,6 +1304,8 @@ mod tests {
None,
None,
true,
+ None,
+ None,
);
let client = ctx.get_client();
assert_eq!(client.api_key(), Some("root-key"));
diff --git a/crates/ov_cli/src/tui/tree.rs b/crates/ov_cli/src/tui/tree.rs
index 3e9954848..710d989fd 100644
--- a/crates/ov_cli/src/tui/tree.rs
+++ b/crates/ov_cli/src/tui/tree.rs
@@ -7,11 +7,11 @@ use crate::client::HttpClient;
pub struct FsEntry {
pub uri: String,
#[serde(default)]
- pub size: Option<u64>,
+ pub _size: Option<u64>,
#[serde(default)]
pub is_dir: bool,
#[serde(default)]
- pub mod_time: Option<String>,
+ pub _mod_time: Option<String>,
}
impl FsEntry {
@@ -69,9 +69,9 @@ impl TreeState {
let mut root_node = TreeNode {
entry: FsEntry {
uri: "/".to_string(),
- size: None,
+ _size: None,
is_dir: true,
- mod_time: None,
+ _mod_time: None,
},
depth: 0,
expanded: true,
@@ -86,9 +86,9 @@ impl TreeState {
let mut node = TreeNode {
entry: FsEntry {
uri: scope_uri.clone(),
- size: None,
+ _size: None,
is_dir: true,
- mod_time: None,
+ _mod_time: None,
},
depth: 1,
expanded: false,
@@ -122,9 +122,9 @@ impl TreeState {
self.nodes = vec![TreeNode {
entry: FsEntry {
uri: format!("(error: {})", e),
- size: None,
+ _size: None,
is_dir: false,
- mod_time: None,
+ _mod_time: None,
},
depth: 0,
expanded: false,