Skip to content

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

feat: support glob -n and cmd echo (#395)

MaojiaSheng358a7c5b7733
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rs
index 937719b06..d8d2f9c9f 100644
--- a/crates/ov_cli/src/client.rs
+++ b/crates/ov_cli/src/client.rs
@@ -410,10 +410,11 @@ impl HttpClient {
}
- pub async fn glob(&self, pattern: &str, uri: &str) -> Result<serde_json::Value> {
+ pub async fn glob(&self, pattern: &str, uri: &str, node_limit: i32) -> Result<serde_json::Value> {
let body = serde_json::json!({
"pattern": pattern,
"uri": uri,
+ "node_limit": node_limit,
});
self.post("/api/v1/search/glob", &body).await
}
diff --git a/crates/ov_cli/src/commands/search.rs b/crates/ov_cli/src/commands/search.rs
index ef68a17f4..633776254 100644
--- a/crates/ov_cli/src/commands/search.rs
+++ b/crates/ov_cli/src/commands/search.rs
@@ -50,10 +50,11 @@ pub async fn glob(
client: &HttpClient,
pattern: &str,
uri: &str,
+ node_limit: i32,
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
- let result = client.glob(pattern, uri).await?;
+ let result = client.glob(pattern, uri, node_limit).await?;
output_success(&result, output_format, compact);
Ok(())
}
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rs
index 93b55461a..1a20a4f87 100644
--- a/crates/ov_cli/src/main.rs
+++ b/crates/ov_cli/src/main.rs
@@ -309,6 +309,9 @@ enum Commands {
/// Search root URI
#[arg(short, long, default_value = "viking://")]
uri: String,
+ /// Maximum number of results
+ #[arg(short = 'n', long = "node-limit", alias = "limit", default_value = "256")]
+ node_limit: i32,
},
/// Add memory in one shot (creates session, adds messages, commits)
AddMemory {
@@ -575,8 +578,8 @@ async fn main() {
handle_grep(uri, pattern, ignore_case, node_limit, ctx).await
}
- Commands::Glob { pattern, uri } => {
- handle_glob(pattern, uri, ctx).await
+ Commands::Glob { pattern, uri, node_limit } => {
+ handle_glob(pattern, uri, node_limit, ctx).await
}
};
@@ -868,6 +871,12 @@ async fn handle_find(
threshold: Option<f64>,
ctx: CliContext,
) -> Result<()> {
+ let mut params = vec![format!("--uri={}", uri), format!("-n {}", node_limit)];
+ if let Some(t) = threshold {
+ params.push(format!("--threshold {}", t));
+ }
+ params.push(format!("\"{}\"", query));
+ print_command_echo("ov find", &params.join(" "), ctx.config.echo_command);
let client = ctx.get_client();
commands::search::find(&client, &query, &uri, node_limit, threshold, ctx.output_format, ctx.compact).await
}
@@ -880,6 +889,15 @@ async fn handle_search(
threshold: Option<f64>,
ctx: CliContext,
) -> Result<()> {
+ let mut params = vec![format!("--uri={}", uri), format!("-n {}", node_limit)];
+ if let Some(s) = &session_id {
+ params.push(format!("--session-id {}", s));
+ }
+ if let Some(t) = threshold {
+ params.push(format!("--threshold {}", t));
+ }
+ params.push(format!("\"{}\"", query));
+ print_command_echo("ov search", &params.join(" "), ctx.config.echo_command);
let client = ctx.get_client();
commands::search::search(&client, &query, &uri, session_id, node_limit, threshold, ctx.output_format, ctx.compact).await
}
@@ -943,14 +961,20 @@ async fn handle_stat(uri: String, ctx: CliContext) -> Result<()> {
}
async fn handle_grep(uri: String, pattern: String, ignore_case: bool, node_limit: i32, ctx: CliContext) -> Result<()> {
+ let mut params = vec![format!("--uri={}", uri), format!("-n {}", node_limit)];
+ if ignore_case { params.push("-i".to_string()); }
+ params.push(format!("\"{}\"", pattern));
+ print_command_echo("ov grep", &params.join(" "), ctx.config.echo_command);
let client = ctx.get_client();
commands::search::grep(&client, &uri, &pattern, ignore_case, node_limit, ctx.output_format, ctx.compact).await
}
-async fn handle_glob(pattern: String, uri: String, ctx: CliContext) -> Result<()> {
+async fn handle_glob(pattern: String, uri: String, node_limit: i32, ctx: CliContext) -> Result<()> {
+ let params = vec![format!("--uri={}", uri), format!("-n {}", node_limit), format!("\"{}\"", pattern)];
+ print_command_echo("ov glob", &params.join(" "), ctx.config.echo_command);
let client = ctx.get_client();
- commands::search::glob(&client, &pattern, &uri, ctx.output_format, ctx.compact).await
+ commands::search::glob(&client, &pattern, &uri, node_limit, ctx.output_format, ctx.compact).await
}
async fn handle_health(ctx: CliContext) -> Result<()> {
diff --git a/openviking/server/routers/search.py b/openviking/server/routers/search.py
index f7b0591b3..73d7309da 100644
--- a/openviking/server/routers/search.py
+++ b/openviking/server/routers/search.py
@@ -52,6 +52,7 @@ class GlobRequest(BaseModel):
pattern: str
uri: str = "viking://"
+ node_limit: Optional[int] = None
@router.post("/find")
@@ -130,5 +131,7 @@ async def glob(
):
"""File pattern matching."""
service = get_service()
- result = await service.fs.glob(request.pattern, ctx=_ctx, uri=request.uri)
+ result = await service.fs.glob(
+ request.pattern, ctx=_ctx, uri=request.uri, node_limit=request.node_limit
+ )
return Response(status="ok", result=result)
diff --git a/openviking/service/fs_service.py b/openviking/service/fs_service.py
index ce3d1a94d..5807e8f10 100644
--- a/openviking/service/fs_service.py
+++ b/openviking/service/fs_service.py
@@ -170,7 +170,13 @@ class FSService:
uri, pattern, case_insensitive=case_insensitive, node_limit=node_limit, ctx=ctx
)
- async def glob(self, pattern: str, ctx: RequestContext, uri: str = "viking://") -> Dict:
+ async def glob(
+ self,
+ pattern: str,
+ ctx: RequestContext,
+ uri: str = "viking://",
+ node_limit: Optional[int] = None,
+ ) -> Dict:
"""File pattern matching."""
viking_fs = self._ensure_initialized()
- return await viking_fs.glob(pattern, uri=uri, ctx=ctx)
+ return await viking_fs.glob(pattern, uri=uri, node_limit=node_limit, ctx=ctx)
diff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.py
index 12fbca952..afa1f9167 100644
--- a/openviking/storage/viking_fs.py
+++ b/openviking/storage/viking_fs.py
@@ -336,17 +336,20 @@ class VikingFS:
self,
pattern: str,
uri: str = "viking://",
- node_limit: int = 1000,
+ node_limit: Optional[int] = None,
ctx: Optional[RequestContext] = None,
) -> Dict:
"""File pattern matching, supports **/*.md recursive."""
- entries = await self.tree(uri, node_limit=node_limit, ctx=ctx)
+ entries = await self.tree(uri, node_limit=1000000, ctx=ctx)
base_uri = uri.rstrip("/")
matches = []
for entry in entries:
rel_path = entry.get("rel_path", "")
if PurePath(rel_path).match(pattern):
matches.append(f"{base_uri}/{rel_path}")
+ # Now apply node limit to the filtered matches
+ if node_limit is not None and node_limit > 0:
+ matches = matches[:node_limit]
return {"matches": matches, "count": len(matches)}
async def _batch_fetch_abstracts(