Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat: dir ignore support in ovcli.conf (#1393)
sentisso7388e4d598e1
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rsindex 04736a808..77afe352e 100644--- a/crates/ov_cli/src/client.rs+++ b/crates/ov_cli/src/client.rs@@ -787,7 +787,11 @@ impl HttpClient {// Determine target pathlet to_path = Path::new(to);let final_path = if to_path.is_dir() {- let base_name = uri.trim_end_matches('/').split('/').last().unwrap_or("export");+ let base_name = uri+ .trim_end_matches('/')+ .split('/')+ .last()+ .unwrap_or("export");to_path.join(format!("{}.ovpack", base_name))} else if !to.ends_with(".ovpack") {Path::new(&format!("{}.ovpack", to)).to_path_buf()@@ -822,10 +826,7 @@ impl HttpClient {)));}if !file_path_obj.is_file() {- return Err(Error::Client(format!(- "Path is not a file: {}",- file_path- )));+ return Err(Error::Client(format!("Path is not a file: {}", file_path)));}let temp_file_id = self.upload_temp_file(file_path_obj).await?;diff --git a/crates/ov_cli/src/commands/search.rs b/crates/ov_cli/src/commands/search.rsindex d9bf713a0..f66386a86 100644--- a/crates/ov_cli/src/commands/search.rs+++ b/crates/ov_cli/src/commands/search.rs@@ -53,7 +53,14 @@ pub async fn grep(compact: bool,) -> Result<()> {let result = client- .grep(uri, exclude_uri, pattern, ignore_case, node_limit, level_limit)+ .grep(+ uri,+ exclude_uri,+ pattern,+ ignore_case,+ node_limit,+ level_limit,+ ).await?;output_success(&result, output_format, compact);Ok(())diff --git a/crates/ov_cli/src/config.rs b/crates/ov_cli/src/config.rsindex ca1c613f1..332b011b8 100644--- a/crates/ov_cli/src/config.rs+++ b/crates/ov_cli/src/config.rs@@ -5,6 +5,23 @@ use crate::error::{Error, Result};const OPENVIKING_CLI_CONFIG_ENV: &str = "OPENVIKING_CLI_CONFIG_FILE";+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct UploadConfig {+ pub ignore_dirs: Option<String>,+ pub include: Option<String>,+ pub exclude: Option<String>,+}++impl Default for UploadConfig {+ fn default() -> Self {+ Self {+ ignore_dirs: None,+ include: None,+ exclude: None,+ }+ }+}+#[derive(Debug, Clone, Serialize, Deserialize)]pub struct Config {#[serde(default = "default_url")]@@ -19,6 +36,8 @@ pub struct Config {pub output: String,#[serde(default = "default_echo_command")]pub echo_command: bool,+ #[serde(default)]+ pub upload: UploadConfig,}fn default_url() -> String {@@ -48,10 +67,35 @@ impl Default for Config {timeout: 60.0,output: "table".to_string(),echo_command: true,+ upload: UploadConfig::default(),}}}+fn normalize_csv_option(value: Option<String>) -> Vec<String> {+ value+ .unwrap_or_default()+ .split(',')+ .map(str::trim)+ .filter(|token| !token.is_empty())+ .map(ToString::to_string)+ .collect()+}++pub fn merge_csv_options(+ config_value: Option<String>,+ cli_value: Option<String>,+) -> Option<String> {+ let mut merged = normalize_csv_option(config_value);+ merged.extend(normalize_csv_option(cli_value));++ if merged.is_empty() {+ None+ } else {+ Some(merged.join(","))+ }+}+impl Config {/// Load config from default location or create defaultpub fn load() -> Result<Self> {@@ -115,7 +159,7 @@ pub fn get_or_create_machine_id() -> Result<String> {#[cfg(test)]mod tests {- use super::Config;+ use super::{Config, merge_csv_options};#[test]fn config_deserializes_account_and_user_fields() {@@ -133,5 +177,77 @@ mod tests {assert_eq!(config.account.as_deref(), Some("acme"));assert_eq!(config.user.as_deref(), Some("alice"));assert_eq!(config.agent_id.as_deref(), Some("assistant-1"));+ assert!(config.upload.ignore_dirs.is_none());+ assert!(config.upload.include.is_none());+ assert!(config.upload.exclude.is_none());+ }++ #[test]+ fn config_deserializes_upload_fields() {+ let config: Config = serde_json::from_str(+ r#"{+ "url": "http://localhost:1933",+ "upload": {+ "ignore_dirs": "node_modules,dist",+ "include": "*.md,*.pdf",+ "exclude": "*.tmp,*.log"+ }+ }"#,+ )+ .expect("config should deserialize");++ assert_eq!(+ config.upload.ignore_dirs.as_deref(),+ Some("node_modules,dist")+ );+ assert_eq!(config.upload.include.as_deref(), Some("*.md,*.pdf"));+ assert_eq!(config.upload.exclude.as_deref(), Some("*.tmp,*.log"));+ }++ #[test]+ fn merge_csv_options_config_only() {+ assert_eq!(+ merge_csv_options(Some("node_modules,dist".to_string()), None),+ Some("node_modules,dist".to_string())+ );+ }++ #[test]+ fn merge_csv_options_cli_only() {+ assert_eq!(+ merge_csv_options(None, Some("*.md,*.pdf".to_string())),+ Some("*.md,*.pdf".to_string())+ );+ }++ #[test]+ fn merge_csv_options_additive_merge() {+ assert_eq!(+ merge_csv_options(+ Some("node_modules,dist".to_string()),+ Some("build,out".to_string())+ ),+ Some("node_modules,dist,build,out".to_string())+ );+ }++ #[test]+ fn merge_csv_options_trims_and_drops_empty_tokens() {+ assert_eq!(+ merge_csv_options(+ Some(" node_modules , , dist ,".to_string()),+ Some(" ,*.tmp, *.log ,".to_string())+ ),+ Some("node_modules,dist,*.tmp,*.log".to_string())+ );+ }++ #[test]+ fn merge_csv_options_returns_none_when_empty() {+ assert_eq!(+ merge_csv_options(Some(" , , ".to_string()), Some("".to_string())),+ None+ );+ assert_eq!(merge_csv_options(None, None), None);}}diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rsindex 8bcea277f..571720c11 100644--- a/crates/ov_cli/src/main.rs+++ b/crates/ov_cli/src/main.rs@@ -7,7 +7,7 @@ mod tui;mod utils;use clap::{ArgAction, Parser, Subcommand};-use config::Config;+use config::{Config, merge_csv_options};use error::{Error, Result};use output::OutputFormat;@@ -784,8 +784,7 @@ async fn main() {append,wait,timeout,- } => handle_write(uri, content, from_file, append, wait, timeout, ctx)- .await,+ } => handle_write(uri, content, from_file, append, wait, timeout, ctx).await,Commands::Reindex {uri,regenerate,@@ -812,7 +811,18 @@ async fn main() {ignore_case,node_limit,level_limit,- } => handle_grep(uri, exclude_uri, pattern, ignore_case, node_limit, level_limit, ctx).await,+ } => {+ handle_grep(+ uri,+ exclude_uri,+ pattern,+ ignore_case,+ node_limit,+ level_limit,+ ctx,+ )+ .await+ }Commands::Glob {pattern,@@ -886,6 +896,11 @@ async fn handle_add_resource(let strict = strict_mode;let directly_upload_media = !no_directly_upload_media;+ let effective_ignore_dirs =+ merge_csv_options(ctx.config.upload.ignore_dirs.clone(), ignore_dirs);+ let effective_include = merge_csv_options(ctx.config.upload.include.clone(), include);+ let effective_exclude = merge_csv_options(ctx.config.upload.exclude.clone(), exclude);+let effective_timeout = if wait {timeout.unwrap_or(60.0).max(ctx.config.timeout)} else {@@ -909,9 +924,9 @@ async fn handle_add_resource(wait,timeout,strict,- ignore_dirs,- include,- exclude,+ effective_ignore_dirs,+ effective_include,+ effective_exclude,directly_upload_media,watch_interval,ctx.output_format,@@ -1237,7 +1252,11 @@ async fn handle_write((Some(value), None) => value,(None, Some(path)) => std::fs::read_to_string(path).map_err(|e| Error::Client(format!("Failed to read --from-file: {}", e)))?,- _ => return Err(Error::Client("Specify exactly one of --content or --from-file".into())),+ _ => {+ return Err(Error::Client(+ "Specify exactly one of --content or --from-file".into(),+ ));+ }};commands::content::write(&client,@@ -1454,7 +1473,11 @@ async fn handle_grep(std::process::exit(1);}- let mut params = vec![format!("--uri={}", uri), format!("-n {}", node_limit), format!("-L {}", level_limit)];+ let mut params = vec![+ format!("--uri={}", uri),+ format!("-n {}", node_limit),+ format!("-L {}", level_limit),+ ];if let Some(excluded) = &exclude_uri {params.push(format!("-x {}", excluded));}@@ -1548,6 +1571,7 @@ mod tests {timeout: 60.0,output: "table".to_string(),echo_command: true,+ upload: Default::default(),};let ctx = CliContext::from_config(diff --git a/crates/ov_cli/src/output.rs b/crates/ov_cli/src/output.rsindex 279eb89b4..c54b555ec 100644--- a/crates/ov_cli/src/output.rs+++ b/crates/ov_cli/src/output.rs@@ -392,19 +392,22 @@ fn render_session_context());lines.push(format!("total_archives {}",- stats.get("totalArchives")+ stats+ .get("totalArchives").map(format_value).unwrap_or_else(|| "0".to_string())));lines.push(format!("included_archives {}",- stats.get("includedArchives")+ stats+ .get("includedArchives").map(format_value).unwrap_or_else(|| "0".to_string())));lines.push(format!("dropped_archives {}",- stats.get("droppedArchives")+ stats+ .get("droppedArchives").map(format_value).unwrap_or_else(|| "0".to_string())));@@ -457,7 +460,9 @@ fn render_session_archive(obj: &serde_json::Map<String, serde_json::Value>,compact: bool,) -> Option<String> {- if !(obj.contains_key("archive_id") && obj.contains_key("overview") && obj.contains_key("messages"))+ if !(obj.contains_key("archive_id")+ && obj.contains_key("overview")+ && obj.contains_key("messages")){return None;}@@ -571,8 +576,14 @@ fn summarize_message_content(parts: Option<&Vec<serde_json::Value>>) -> String {});}"tool" => {- let name = obj.get("tool_name").and_then(|v| v.as_str()).unwrap_or("tool");- let status = obj.get("tool_status").and_then(|v| v.as_str()).unwrap_or("");+ let name = obj+ .get("tool_name")+ .and_then(|v| v.as_str())+ .unwrap_or("tool");+ let status = obj+ .get("tool_status")+ .and_then(|v| v.as_str())+ .unwrap_or("");chunks.push(if status.is_empty() {format!("[tool:{}]", name)} else {diff --git a/docs/en/guides/01-configuration.md b/docs/en/guides/01-configuration.mdindex da4afc629..9e114b44c 100644--- a/docs/en/guides/01-configuration.md+++ b/docs/en/guides/01-configuration.md@@ -794,7 +794,12 @@ Config file for the HTTP client (`SyncHTTPClient` / `AsyncHTTPClient`) and CLI t"account": "acme","user": "alice","agent_id": "my-agent",- "output": "table"+ "output": "table",+ "upload": {+ "ignore_dirs": "node_modules,.cache,.nx",+ "include": "*.md,*.pdf",+ "exclude": "*.tmp,*.log"+ }}```@@ -806,6 +811,9 @@ Config file for the HTTP client (`SyncHTTPClient` / `AsyncHTTPClient`) and CLI t| `user` | Default user sent as `X-OpenViking-User` | `null` || `agent_id` | Agent identifier for agent space isolation | `null` || `output` | Default output format: `"table"` or `"json"` | `"table"` |+| `upload.ignore_dirs` | Default directory ignore list for `add-resource` (CSV) | `null` |+| `upload.include` | Default include patterns for `add-resource` (CSV) | `null` |+| `upload.exclude` | Default exclude patterns for `add-resource` (CSV) | `null` |CLI flags can override these identity fields per command:@@ -813,6 +821,14 @@ CLI flags can override these identity fields per command:openviking --account acme --user alice --agent-id assistant-2 ls viking://```+For `add-resource`, upload filter flags are merged additively with `ovcli.conf` defaults:++```bash+# ovcli.conf: upload.exclude="*.log"+openviking add-resource ./docs --exclude "*.tmp"+# effective exclude sent to server: "*.log,*.tmp"+```+See [Deployment](./03-deployment.md) for details.## server Sectiondiff --git a/docs/zh/guides/01-configuration.md b/docs/zh/guides/01-configuration.mdindex 15c563d2c..12774f5f9 100644--- a/docs/zh/guides/01-configuration.md+++ b/docs/zh/guides/01-configuration.md@@ -767,7 +767,12 @@ HTTP 客户端(`SyncHTTPClient` / `AsyncHTTPClient`)和 CLI 工具连接远"account": "acme","user": "alice","agent_id": "my-agent",- "output": "table"+ "output": "table",+ "upload": {+ "ignore_dirs": "node_modules,.cache,.nx",+ "include": "*.md,*.pdf",+ "exclude": "*.tmp,*.log"+ }}```@@ -779,6 +784,9 @@ HTTP 客户端(`SyncHTTPClient` / `AsyncHTTPClient`)和 CLI 工具连接远| `user` | 默认发送为 `X-OpenViking-User` 的用户标识 | `null` || `agent_id` | Agent 标识,用于 agent space 隔离 | `null` || `output` | 默认输出格式:`"table"` 或 `"json"` | `"table"` |+| `upload.ignore_dirs` | `add-resource` 默认忽略目录列表(CSV) | `null` |+| `upload.include` | `add-resource` 默认包含模式(CSV) | `null` |+| `upload.exclude` | `add-resource` 默认排除模式(CSV) | `null` |也可以在单次命令里用 CLI 参数覆盖这些身份字段:@@ -786,6 +794,14 @@ HTTP 客户端(`SyncHTTPClient` / `AsyncHTTPClient`)和 CLI 工具连接远openviking --account acme --user alice --agent-id assistant-2 ls viking://```+对于 `add-resource`,上传过滤参数会与 `ovcli.conf` 默认值做合并(追加),不会覆盖:++```bash+# ovcli.conf: upload.exclude="*.log"+openviking add-resource ./docs --exclude "*.tmp"+# 实际发送给服务端的 exclude: "*.log,*.tmp"+```+详见 [服务部署](./03-deployment.md)。## server 段diff --git a/openviking_cli/utils/config/ovcli_config.py b/openviking_cli/utils/config/ovcli_config.pyindex cb1b27068..a8ac66d95 100644--- a/openviking_cli/utils/config/ovcli_config.py+++ b/openviking_cli/utils/config/ovcli_config.py@@ -12,6 +12,16 @@ from .config_utils import format_validation_errorfrom .consts import DEFAULT_OVCLI_CONF, OPENVIKING_CLI_CONFIG_ENV+class OVCLIUploadConfig(BaseModel):+ """Upload-related defaults in ovcli.conf."""++ ignore_dirs: Optional[str] = None+ include: Optional[str] = None+ exclude: Optional[str] = None++ model_config = {"extra": "forbid"}++class OVCLIConfig(BaseModel):"""Client configuration loaded from ovcli.conf."""@@ -21,6 +31,7 @@ class OVCLIConfig(BaseModel):account: Optional[str] = Noneuser: Optional[str] = Nonetimeout: float = 60.0+ upload: Optional[OVCLIUploadConfig] = Nonemodel_config = {"extra": "forbid"}diff --git a/tests/client/test_http_client_config.py b/tests/client/test_http_client_config.pyindex 1f97f4735..9b86a2293 100644--- a/tests/client/test_http_client_config.py+++ b/tests/client/test_http_client_config.py@@ -77,3 +77,44 @@ def test_async_http_client_reports_invalid_ovcli_value_path(tmp_path, monkeypatcwith pytest.raises(ValueError, match=r"Invalid value for 'ovcli\.timeout'"):AsyncHTTPClient()+++def test_async_http_client_accepts_ovcli_upload_section(tmp_path, monkeypatch):+ config_path = tmp_path / "ovcli.conf"+ config_path.write_text(+ json.dumps(+ {+ "url": "http://config-host:1933",+ "api_key": "config-key",+ "upload": {+ "ignore_dirs": "node_modules,.cache",+ "include": "*.md,*.pdf",+ "exclude": "*.tmp,*.log",+ },+ }+ )+ )+ monkeypatch.setenv("OPENVIKING_CLI_CONFIG_FILE", str(config_path))++ client = AsyncHTTPClient()++ assert client._url == "http://config-host:1933"+ assert client._api_key == "config-key"+++def test_async_http_client_rejects_unknown_ovcli_upload_field(tmp_path, monkeypatch):+ config_path = tmp_path / "ovcli.conf"+ config_path.write_text(+ json.dumps(+ {+ "url": "http://localhost:1933",+ "upload": {+ "unknown": "value",+ },+ }+ )+ )+ monkeypatch.setenv("OPENVIKING_CLI_CONFIG_FILE", str(config_path))++ with pytest.raises(ValueError, match=r"ovcli\.upload\.unknown"):+ AsyncHTTPClient()