Skip to content

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

fix(add-resource): improve directory import UX and correctness (#1197)

yangxinxin-7fe778d8f806c
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rs
index e5729327e..766878e24 100644
--- a/crates/ov_cli/src/client.rs
+++ b/crates/ov_cli/src/client.rs
@@ -565,11 +565,16 @@ impl HttpClient {
if path_obj.exists() {
if path_obj.is_dir() {
+ let source_name = path_obj
+ .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 body = serde_json::json!({
"temp_file_id": temp_file_id,
+ "source_name": source_name,
"to": to,
"parent": parent,
"reason": reason,
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rs
index 1ef5bf899..3bae0bf51 100644
--- a/crates/ov_cli/src/main.rs
+++ b/crates/ov_cli/src/main.rs
@@ -6,7 +6,7 @@ mod output;
mod tui;
mod utils;
-use clap::{Parser, Subcommand};
+use clap::{ArgAction, Parser, Subcommand};
use config::Config;
use error::{Error, Result};
use output::OutputFormat;
@@ -128,9 +128,9 @@ enum Commands {
/// Wait timeout in seconds (only used with --wait)
#[arg(long)]
timeout: Option<f64>,
- /// No strict mode for directory scanning
- #[arg(long = "no-strict", default_value_t = false)]
- no_strict: bool,
+ /// Enable strict mode for directory scanning (fail if any unsupported files found)
+ #[arg(long = "strict", action = ArgAction::SetTrue)]
+ strict_mode: bool,
/// Ignore directories, e.g. --ignore-dirs "node_modules,dist"
#[arg(long)]
ignore_dirs: Option<String>,
@@ -660,7 +660,7 @@ async fn main() {
instruction,
wait,
timeout,
- no_strict,
+ strict_mode,
ignore_dirs,
include,
exclude,
@@ -675,7 +675,7 @@ async fn main() {
instruction,
wait,
timeout,
- no_strict,
+ strict_mode,
ignore_dirs,
include,
exclude,
@@ -831,7 +831,7 @@ async fn handle_add_resource(
instruction: String,
wait: bool,
timeout: Option<f64>,
- no_strict: bool,
+ strict_mode: bool,
ignore_dirs: Option<String>,
include: Option<String>,
exclude: Option<String>,
@@ -879,7 +879,7 @@ async fn handle_add_resource(
std::process::exit(1);
}
- let strict = !no_strict;
+ let strict = strict_mode;
let directly_upload_media = !no_directly_upload_media;
let effective_timeout = if wait {
diff --git a/openviking/parse/directory_scan.py b/openviking/parse/directory_scan.py
index 151b850aa..0e8904e3f 100644
--- a/openviking/parse/directory_scan.py
+++ b/openviking/parse/directory_scan.py
@@ -289,9 +289,6 @@ def scan_directory(
raise UnsupportedDirectoryFilesError(msg, unsupported_paths)
else:
logger.warning(msg)
- result.warnings.append(msg)
- for rel in unsupported_paths:
- result.warnings.append(f" - {rel}")
result.processable.sort(key=lambda x: x.rel_path)
result.unsupported.sort(key=lambda x: x.rel_path)
diff --git a/openviking/parse/parsers/constants.py b/openviking/parse/parsers/constants.py
index 3377d78f3..33622a7c1 100644
--- a/openviking/parse/parsers/constants.py
+++ b/openviking/parse/parsers/constants.py
@@ -95,6 +95,7 @@ IGNORE_EXTENSIONS = {
# Code file extensions for file type detection
CODE_EXTENSIONS = {
".py",
+ ".pyi",
".java",
".cpp",
".cc",
@@ -227,6 +228,8 @@ ADDITIONAL_TEXT_EXTENSIONS = {
".yarnrc",
".env",
".env.example",
+ ".lock",
+ ".in",
}
# Common text encodings to try for encoding detection (in order of likelihood)
diff --git a/openviking/parse/parsers/directory.py b/openviking/parse/parsers/directory.py
index 0244b3d65..d8d2b1c98 100644
--- a/openviking/parse/parsers/directory.py
+++ b/openviking/parse/parsers/directory.py
@@ -87,7 +87,7 @@ class DirectoryParser(BaseParser):
if not source_path.is_dir():
raise NotADirectoryError(f"Not a directory: {source_path}")
- dir_name = source_path.name
+ dir_name = kwargs.get("source_name") or source_path.name
warnings: List[str] = []
try:
diff --git a/openviking/server/routers/resources.py b/openviking/server/routers/resources.py
index f9c3275f1..45ac3f3db 100644
--- a/openviking/server/routers/resources.py
+++ b/openviking/server/routers/resources.py
@@ -73,7 +73,8 @@ class AddResourceRequest(BaseModel):
instruction: str = ""
wait: bool = False
timeout: Optional[float] = None
- strict: bool = True
+ strict: bool = False
+ source_name: Optional[str] = None
ignore_dirs: Optional[str] = None
include: Optional[str] = None
exclude: Optional[str] = None
@@ -190,6 +191,7 @@ async def add_resource(
kwargs = {
"strict": request.strict,
+ "source_name": request.source_name,
"ignore_dirs": request.ignore_dirs,
"include": request.include,
"exclude": request.exclude,
diff --git a/openviking/utils/resource_processor.py b/openviking/utils/resource_processor.py
index 320c6e51d..c12109c79 100644
--- a/openviking/utils/resource_processor.py
+++ b/openviking/utils/resource_processor.py
@@ -153,7 +153,7 @@ class ResourceProcessor:
return result
if parse_result.warnings:
- result["errors"].extend(parse_result.warnings)
+ result.setdefault("warnings", []).extend(parse_result.warnings)
telemetry.set(
"resource.parse.duration_ms",