Skip to content

Commit e4b1ffe

Browse files
MaojiaShengopenviking
andauthored
Feat: CLI optimization (#389)
* feat: remove python cli and disable python -m openviking * feat: ls, tree, find, search, grep all use --node-limit as the result limiting arg * feat: add ls -n * feat: update agfs to support grep -n * feat: update agfs to support grep -n * docs: cancel modify --------- Co-authored-by: openviking <openviking@example.com>
1 parent 913bc75 commit e4b1ffe

File tree

35 files changed

+202
-4357
lines changed

35 files changed

+202
-4357
lines changed

crates/ov_cli/src/client.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ impl HttpClient {
369369
&self,
370370
query: String,
371371
uri: String,
372-
limit: i32,
372+
node_limit: i32,
373373
threshold: Option<f64>,
374374
) -> Result<serde_json::Value> {
375375
let body = serde_json::json!({
376376
"query": query,
377377
"target_uri": uri,
378-
"limit": limit,
378+
"limit": node_limit,
379379
"score_threshold": threshold,
380380
});
381381
self.post("/api/v1/search/find", &body).await
@@ -386,28 +386,30 @@ impl HttpClient {
386386
query: String,
387387
uri: String,
388388
session_id: Option<String>,
389-
limit: i32,
389+
node_limit: i32,
390390
threshold: Option<f64>,
391391
) -> Result<serde_json::Value> {
392392
let body = serde_json::json!({
393393
"query": query,
394394
"target_uri": uri,
395395
"session_id": session_id,
396-
"limit": limit,
396+
"limit": node_limit,
397397
"score_threshold": threshold,
398398
});
399399
self.post("/api/v1/search/search", &body).await
400400
}
401401

402-
pub async fn grep(&self, uri: &str, pattern: &str, ignore_case: bool) -> Result<serde_json::Value> {
402+
pub async fn grep(&self, uri: &str, pattern: &str, ignore_case: bool, node_limit: i32) -> Result<serde_json::Value> {
403403
let body = serde_json::json!({
404404
"uri": uri,
405405
"pattern": pattern,
406406
"case_insensitive": ignore_case,
407+
"node_limit": node_limit,
407408
});
408409
self.post("/api/v1/search/grep", &body).await
409410
}
410411

412+
411413
pub async fn glob(&self, pattern: &str, uri: &str) -> Result<serde_json::Value> {
412414
let body = serde_json::json!({
413415
"pattern": pattern,

crates/ov_cli/src/commands/search.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub async fn find(
66
client: &HttpClient,
77
query: &str,
88
uri: &str,
9-
limit: i32,
9+
node_limit: i32,
1010
threshold: Option<f64>,
1111
output_format: OutputFormat,
1212
compact: bool,
1313
) -> Result<()> {
14-
let result = client.find(query.to_string(), uri.to_string(), limit, threshold).await?;
14+
let result = client.find(query.to_string(), uri.to_string(), node_limit, threshold).await?;
1515
output_success(&result, output_format, compact);
1616
Ok(())
1717
}
@@ -21,12 +21,12 @@ pub async fn search(
2121
query: &str,
2222
uri: &str,
2323
session_id: Option<String>,
24-
limit: i32,
24+
node_limit: i32,
2525
threshold: Option<f64>,
2626
output_format: OutputFormat,
2727
compact: bool,
2828
) -> Result<()> {
29-
let result = client.search(query.to_string(), uri.to_string(), session_id, limit, threshold).await?;
29+
let result = client.search(query.to_string(), uri.to_string(), session_id, node_limit, threshold).await?;
3030
output_success(&result, output_format, compact);
3131
Ok(())
3232
}
@@ -36,14 +36,16 @@ pub async fn grep(
3636
uri: &str,
3737
pattern: &str,
3838
ignore_case: bool,
39+
node_limit: i32,
3940
output_format: OutputFormat,
4041
compact: bool,
4142
) -> Result<()> {
42-
let result = client.grep(uri, pattern, ignore_case).await?;
43+
let result = client.grep(uri, pattern, ignore_case, node_limit).await?;
4344
output_success(&result, output_format, compact);
4445
Ok(())
4546
}
4647

48+
4749
pub async fn glob(
4850
client: &HttpClient,
4951
pattern: &str,

crates/ov_cli/src/main.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ enum Commands {
195195
#[arg(short, long)]
196196
all: bool,
197197
/// Maximum number of nodes to list
198-
#[arg(long = "node-limit", short = 'n', default_value = "256")]
198+
#[arg(long = "node-limit", short = 'n', alias = "limit", default_value = "256")]
199199
node_limit: i32,
200200
},
201201
/// Get directory tree
@@ -209,7 +209,7 @@ enum Commands {
209209
#[arg(short, long)]
210210
all: bool,
211211
/// Maximum number of nodes to list
212-
#[arg(long = "node-limit", short = 'n', default_value = "256")]
212+
#[arg(long = "node-limit", short = 'n', alias = "limit", default_value = "256")]
213213
node_limit: i32,
214214
/// Maximum depth level to traverse (default: 3)
215215
#[arg(short = 'L', long = "level-limit", default_value = "3")]
@@ -265,8 +265,8 @@ enum Commands {
265265
#[arg(short, long, default_value = "")]
266266
uri: String,
267267
/// Maximum number of results
268-
#[arg(short = 'n', long, default_value = "10")]
269-
limit: i32,
268+
#[arg(short = 'n', long = "node-limit", alias = "limit", default_value = "10")]
269+
node_limit: i32,
270270
/// Score threshold
271271
#[arg(short, long)]
272272
threshold: Option<f64>,
@@ -282,8 +282,8 @@ enum Commands {
282282
#[arg(long)]
283283
session_id: Option<String>,
284284
/// Maximum number of results
285-
#[arg(short = 'n', long, default_value = "10")]
286-
limit: i32,
285+
#[arg(short = 'n', long = "node-limit", alias = "limit", default_value = "10")]
286+
node_limit: i32,
287287
/// Score threshold
288288
#[arg(short, long)]
289289
threshold: Option<f64>,
@@ -298,6 +298,9 @@ enum Commands {
298298
/// Case insensitive
299299
#[arg(short, long)]
300300
ignore_case: bool,
301+
/// Maximum number of results
302+
#[arg(short = 'n', long = "node-limit", alias = "limit", default_value = "256")]
303+
node_limit: i32,
301304
},
302305
/// Run file glob pattern search
303306
Glob {
@@ -562,15 +565,16 @@ async fn main() {
562565
Commands::Read { uri } => handle_read(uri, ctx).await,
563566
Commands::Abstract { uri } => handle_abstract(uri, ctx).await,
564567
Commands::Overview { uri } => handle_overview(uri, ctx).await,
565-
Commands::Find { query, uri, limit, threshold } => {
566-
handle_find(query, uri, limit, threshold, ctx).await
568+
Commands::Find { query, uri, node_limit, threshold } => {
569+
handle_find(query, uri, node_limit, threshold, ctx).await
567570
}
568-
Commands::Search { query, uri, session_id, limit, threshold } => {
569-
handle_search(query, uri, session_id, limit, threshold, ctx).await
571+
Commands::Search { query, uri, session_id, node_limit, threshold } => {
572+
handle_search(query, uri, session_id, node_limit, threshold, ctx).await
570573
}
571-
Commands::Grep { uri, pattern, ignore_case } => {
572-
handle_grep(uri, pattern, ignore_case, ctx).await
574+
Commands::Grep { uri, pattern, ignore_case, node_limit } => {
575+
handle_grep(uri, pattern, ignore_case, node_limit, ctx).await
573576
}
577+
574578
Commands::Glob { pattern, uri } => {
575579
handle_glob(pattern, uri, ctx).await
576580
}
@@ -860,24 +864,24 @@ async fn handle_overview(uri: String, ctx: CliContext) -> Result<()> {
860864
async fn handle_find(
861865
query: String,
862866
uri: String,
863-
limit: i32,
867+
node_limit: i32,
864868
threshold: Option<f64>,
865869
ctx: CliContext,
866870
) -> Result<()> {
867871
let client = ctx.get_client();
868-
commands::search::find(&client, &query, &uri, limit, threshold, ctx.output_format, ctx.compact).await
872+
commands::search::find(&client, &query, &uri, node_limit, threshold, ctx.output_format, ctx.compact).await
869873
}
870874

871875
async fn handle_search(
872876
query: String,
873877
uri: String,
874878
session_id: Option<String>,
875-
limit: i32,
879+
node_limit: i32,
876880
threshold: Option<f64>,
877881
ctx: CliContext,
878882
) -> Result<()> {
879883
let client = ctx.get_client();
880-
commands::search::search(&client, &query, &uri, session_id, limit, threshold, ctx.output_format, ctx.compact).await
884+
commands::search::search(&client, &query, &uri, session_id, node_limit, threshold, ctx.output_format, ctx.compact).await
881885
}
882886

883887
/// Print command with specified parameters for debugging
@@ -938,11 +942,12 @@ async fn handle_stat(uri: String, ctx: CliContext) -> Result<()> {
938942
commands::filesystem::stat(&client, &uri, ctx.output_format, ctx.compact).await
939943
}
940944

941-
async fn handle_grep(uri: String, pattern: String, ignore_case: bool, ctx: CliContext) -> Result<()> {
945+
async fn handle_grep(uri: String, pattern: String, ignore_case: bool, node_limit: i32, ctx: CliContext) -> Result<()> {
942946
let client = ctx.get_client();
943-
commands::search::grep(&client, &uri, &pattern, ignore_case, ctx.output_format, ctx.compact).await
947+
commands::search::grep(&client, &uri, &pattern, ignore_case, node_limit, ctx.output_format, ctx.compact).await
944948
}
945949

950+
946951
async fn handle_glob(pattern: String, uri: String, ctx: CliContext) -> Result<()> {
947952
let client = ctx.get_client();
948953
commands::search::glob(&client, &pattern, &uri, ctx.output_format, ctx.compact).await

0 commit comments

Comments
 (0)