feat: add client mode with streaming support
Add client mode enabling the keep CLI to connect to a remote keep server over HTTP. Local plugins (compression, meta, filters) run on the client; the server stores/retrieves binary blobs. Architecture: - Client save uses 3-thread streaming pipeline: reader thread (stdin → tee/stdout → hash → compress), OS pipe, streamer thread (pipe → chunked HTTP POST). Memory usage is O(PIPESIZE) regardless of data size. - Server accepts compress=false, meta=false, decompress=false query params for granular control of server-side processing. - Streaming body handling on server via async channel → sync reader bridge (ChannelReader). Key additions: - src/client.rs: KeepClient with post_stream() for chunked upload - src/modes/client/: save, get, list, info, delete, diff, status - --client-url / KEEP_CLIENT_URL configuration - --client-password / KEEP_CLIENT_PASSWORD for auth - os_pipe dependency for zero-copy pipe streaming Co-Authored-By: andrew/openrouter/hunter-alpha <noreply@opencode.ai>
This commit is contained in:
55
src/modes/client/list.rs
Normal file
55
src/modes/client/list.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use crate::client::KeepClient;
|
||||
use crate::modes::common::{OutputFormat, format_size, settings_output_format};
|
||||
use clap::Command;
|
||||
use log::debug;
|
||||
|
||||
pub fn mode(
|
||||
client: &KeepClient,
|
||||
_cmd: &mut Command,
|
||||
settings: &crate::config::Settings,
|
||||
tags: &[String],
|
||||
) -> Result<(), anyhow::Error> {
|
||||
debug!("CLIENT_LIST: Listing items via remote server");
|
||||
|
||||
let items = client.list_items(tags, "newest", 0, 100)?;
|
||||
|
||||
let output_format = settings_output_format(settings);
|
||||
|
||||
match output_format {
|
||||
OutputFormat::Json => {
|
||||
println!("{}", serde_json::to_string_pretty(&items)?);
|
||||
}
|
||||
OutputFormat::Yaml => {
|
||||
println!("{}", serde_yaml::to_string(&items)?);
|
||||
}
|
||||
OutputFormat::Table => {
|
||||
use comfy_table::{Table, presets::UTF8_FULL};
|
||||
|
||||
let mut table = Table::new();
|
||||
table.load_preset(UTF8_FULL);
|
||||
|
||||
// Header
|
||||
let headers = ["ID", "Time", "Size", "Compression", "Tags"];
|
||||
table.set_header(headers.iter().map(|h| h.to_string()).collect::<Vec<_>>());
|
||||
|
||||
for item in &items {
|
||||
let size_str = item
|
||||
.size
|
||||
.map(|s| format_size(s as u64, settings.human_readable))
|
||||
.unwrap_or_default();
|
||||
|
||||
table.add_row(vec![
|
||||
item.id.to_string(),
|
||||
item.ts.clone(),
|
||||
size_str,
|
||||
item.compression.clone(),
|
||||
item.tags.join(", "),
|
||||
]);
|
||||
}
|
||||
|
||||
println!("{table}");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user