Skip to content

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

fix: short markdown parse filename (#176)

MaojiaShengf7dfb95ea96e
diff --git a/openviking/parse/parsers/markdown.py b/openviking/parse/parsers/markdown.py
index fc66f9353..e6ddbe3ad 100644
--- a/openviking/parse/parsers/markdown.py
+++ b/openviking/parse/parsers/markdown.py
@@ -50,6 +50,7 @@ class MarkdownParser(BaseParser):
# Configuration constants
DEFAULT_MAX_SECTION_SIZE = 1024 # Maximum tokens per section
DEFAULT_MIN_SECTION_TOKENS = 512 # Minimum tokens to create a separate section
+ MAX_MERGED_FILENAME_LENGTH = 32 # Maximum length for merged section filenames
def __init__(
self,
@@ -564,14 +565,40 @@ class MarkdownParser(BaseParser):
for i, part in enumerate(parts, 1):
await viking_fs.write_file(f"{section_dir}/{name}_{i}.md", part)
+ def _generate_merged_filename(self, sections: List[Tuple[str, str, int]]) -> str:
+ """
+ Smart merged filename generation, limited to MAX_MERGED_FILENAME_LENGTH characters.
+
+ Strategy:
+ - Single section: Use directly (truncated to MAX_MERGED_FILENAME_LENGTH chars)
+ - Multiple sections: {first_section}_{count}more (e.g., Intro_3more)
+ - Total length strictly limited: MAX_MERGED_FILENAME_LENGTH characters
+ """
+ if not sections:
+ return "merged"
+
+ names = [n for n, _, _ in sections]
+ count = len(names)
+
+ if count == 1:
+ name = names[0][: self.MAX_MERGED_FILENAME_LENGTH]
+ else:
+ suffix = f"_{count}more"
+ max_first_len = self.MAX_MERGED_FILENAME_LENGTH - len(suffix)
+ first_name = names[0][: max(max_first_len, 1)]
+ name = f"{first_name}{suffix}"
+
+ name = name[: self.MAX_MERGED_FILENAME_LENGTH].strip("_")
+ return name or "merged"
+
async def _save_merged(
self, viking_fs, parent_dir: str, sections: List[Tuple[str, str, int]]
) -> None:
- """Save merged sections as single file."""
- name = "_".join(n for n, _, _ in sections)
+ """Save merged sections as single file with smart naming."""
+ name = self._generate_merged_filename(sections)
content = "\n\n".join(c for _, c, _ in sections)
await viking_fs.write_file(f"{parent_dir}/{name}.md", content)
- logger.debug(f"[MarkdownParser] Merged: {name}.md")
+ logger.debug(f"[MarkdownParser] Merged: {name}.md ({len(sections)} sections)")
def _get_section_info(
self,
diff --git a/openviking_cli/cli/commands/filesystem.py b/openviking_cli/cli/commands/filesystem.py
index 1aef4c820..9b7765627 100644
--- a/openviking_cli/cli/commands/filesystem.py
+++ b/openviking_cli/cli/commands/filesystem.py
@@ -50,7 +50,9 @@ def register(app: typer.Typer) -> None:
abs_limit: int = typer.Option(128, "--abs-limit", "-l", help="Abstract content limit"),
show_all_hidden: bool = typer.Option(False, "--all", "-a", help="Show all hidden files"),
) -> None:
- """Get directory tree."""
+ """
+ Get directory tree info.
+ """
run(
ctx,
lambda client: client.tree(