OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: 导入含嵌套子 skill 的目录时,嵌套 SKILL.md 文件被静默丢弃

Open hachimin-wh opened this issue 3 months ago • 0 comments

Issue Origin

Observed or reproduced in a real environment

Bug Description

通过目录或 ZIP 导入组合 skill 时,SkillProcessor 会静默丢弃嵌套子模块中的 SKILL.md 文件。导入接口返回成功且无错误日志,但最终保存的 skill 数据不完整。

受影响代码为 openviking/utils/skill_processor.py,并由 resources.add_skill 与 POST /api/v1/skills 使用。

Steps to Reproduce

  1. 准备如下目录: my-skill/ ├── SKILL.md ├── script.cjs ├── notes/ │ └── SKILL.md └── knowledge-base/ └── SKILL.md

  2. 将目录打包为 ZIP,通过 POST /api/v1/resources/temp_upload 上传。

  3. 使用返回的 temp_file_id 调用 POST /api/v1/skills。直接以目录方式导入也可以复现。

  4. 使用 GET /api/v1/skills/my-skill 检查导入后的文件。

  5. 可以看到 notes/SKILL.md 和 knowledge-base/SKILL.md 均未保存。

Expected Behavior

只排除作为 skill 主体解析的顶层 SKILL.md;notes/SKILL.md、knowledge-base/SKILL.md 等嵌套文件应作为辅助文件保存。

Actual Behavior

遍历目录树时,所有文件名为 SKILL.md 的文件都被排除。导入仍返回 success,但嵌套子模块文档被静默丢弃。

Minimal Reproducible Example

from pathlib import Path
from openviking.utils.skill_processor import SkillProcessor

skill_dir = Path("my-skill")
proc = SkillProcessor(vikingdb=None)

skill_dict, aux, base, cleanup = proc._parse_skill(
    skill_dir,
    allow_local_path_resolution=True,
)

print(sorted(str(p.relative_to(skill_dir)) for p in aux))

# 实际: ['script.cjs']
# 期望: ['knowledge-base/SKILL.md', 'notes/SKILL.md', 'script.cjs']

Error Logs

无异常日志。该问题会静默丢失文件,导入接口仍返回成功。

OpenViking Version

0.4.14.dev80 (main, commit dbf3fccc; upstream/main verified affected)

Python Version

3.12.10

Operating System

macOS

Model Backend

Other

Additional Context

根因:

for item in data.rglob("*"):
    if item.is_file() and item.name != "SKILL.md":
        auxiliary_files.append(item)

item.name != "SKILL.md" 排除了整棵目录树中所有同名文件,而意图只是排除顶层 skill 主体。

建议修复:

for item in data.rglob("*"):
    if item.is_file() and item != skill_file:
        auxiliary_files.append(item)

已在本地验证:修复后嵌套 SKILL.md 正确保留;通过 PUT /api/v1/skills/{name} 重新导入后,辅助文件数从 6 恢复为 8。

对应修复 PR:#4055

hachimin-wh avatar Aug 17 '26 08:08 hachimin-wh