feat: 知识库文件夹/模板、技能压缩设置与摘要窗口调优
- 知识库新增文件夹与模板支持(模型/仓储/服务/迁移),前端知识管理组件 - 岗位管理模型与接口完善 - 技能新增压缩设置页与相关存储/工具能力 - 系统设置扩展配置项 - 摘要中间件 keep 窗口改用 token 预算(16000),减少重复压缩 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e6662cf673
commit
5ebbb82d66
54 files changed
+2658
-100
No files matched your search
+53
-5
@@ -54,11 +54,42 @@ class LocalSkillStorage(SkillStorage):
|
||||
return self._host_root
|
||||
|
||||
def custom_skill_exists(self, name: str) -> bool:
|
||||
return self.get_custom_skill_file(name).exists()
|
||||
return self._resolve_skill_dir(name, SkillCategory.CUSTOM) is not None
|
||||
|
||||
def public_skill_exists(self, name: str) -> bool:
|
||||
return self._resolve_skill_dir(name, SkillCategory.PUBLIC) is not None
|
||||
|
||||
def _resolve_skill_dir(self, name: str, category: SkillCategory) -> Path | None:
|
||||
"""Return the on-disk directory of the skill identified by *name*.
|
||||
|
||||
Discovery (``_iter_skill_files``/``load_skills``) keys a skill by the
|
||||
``name`` in its SKILL.md frontmatter, but a hand-dropped or mis-extracted
|
||||
skill can live at a directory whose name differs from that frontmatter
|
||||
name. Locating a skill by the canonical ``<category>/<name>`` path alone
|
||||
would then make it *listable but not deletable/readable*.
|
||||
|
||||
Fast path: the canonical ``<category>/<name>`` layout. Fallback: scan the
|
||||
discovered SKILL.md files and match on the parsed frontmatter ``name`` so
|
||||
delete/read/editability stay consistent with what discovery surfaces.
|
||||
Returns ``None`` when no such skill is discoverable.
|
||||
"""
|
||||
from deerflow.skills.parser import parse_skill_file
|
||||
|
||||
normalized_name = self.validate_skill_name(name)
|
||||
return (self._host_root / SkillCategory.PUBLIC.value / normalized_name / SKILL_MD_FILE).exists()
|
||||
canonical = self._host_root / category.value / normalized_name
|
||||
if (canonical / SKILL_MD_FILE).is_file():
|
||||
return canonical
|
||||
for found_category, category_root, md_path in self._iter_skill_files():
|
||||
if found_category != category:
|
||||
continue
|
||||
skill = parse_skill_file(
|
||||
md_path,
|
||||
category=found_category,
|
||||
relative_path=md_path.parent.relative_to(category_root),
|
||||
)
|
||||
if skill and skill.name == normalized_name:
|
||||
return md_path.parent
|
||||
return None
|
||||
|
||||
def _iter_skill_files(self) -> Iterable[tuple[SkillCategory, Path, Path]]:
|
||||
if not self._host_root.exists():
|
||||
@@ -71,12 +102,19 @@ class LocalSkillStorage(SkillStorage):
|
||||
dir_names[:] = sorted(name for name in dir_names if not name.startswith("."))
|
||||
if SKILL_MD_FILE not in file_names:
|
||||
continue
|
||||
# A directory containing SKILL.md *is* a self-contained skill;
|
||||
# treat it as a leaf and do not descend into its subdirectories.
|
||||
# This keeps bundled assets that ship their own SKILL.md (e.g.
|
||||
# ``examples/`` or ``references/`` inside a skill package) from
|
||||
# being surfaced as separate, undeletable top-level skills.
|
||||
dir_names[:] = []
|
||||
yield category, category_path, Path(current_root) / SKILL_MD_FILE
|
||||
|
||||
def read_custom_skill(self, name: str) -> str:
|
||||
if not self.custom_skill_exists(name):
|
||||
skill_dir = self._resolve_skill_dir(name, SkillCategory.CUSTOM)
|
||||
if skill_dir is None:
|
||||
raise FileNotFoundError(f"Custom skill '{name}' not found.")
|
||||
return (self.get_custom_skill_dir(name) / SKILL_MD_FILE).read_text(encoding="utf-8")
|
||||
return (skill_dir / SKILL_MD_FILE).read_text(encoding="utf-8")
|
||||
|
||||
def write_custom_skill(self, name: str, relative_path: str, content: str) -> None:
|
||||
target = self.validate_relative_path(relative_path, self.get_custom_skill_dir(name))
|
||||
@@ -251,7 +289,17 @@ class LocalSkillStorage(SkillStorage):
|
||||
def delete_custom_skill(self, name: str, *, history_meta: dict | None = None) -> None:
|
||||
self.validate_skill_name(name)
|
||||
self.ensure_custom_skill_is_editable(name)
|
||||
target = self.get_custom_skill_dir(name)
|
||||
# Delete the skill's *discovered* directory, not the assumed
|
||||
# ``custom/<name>`` path — a skill placed at a non-canonical or nested
|
||||
# location must still be removable now that discovery surfaced it.
|
||||
target = self._resolve_skill_dir(name, SkillCategory.CUSTOM)
|
||||
if target is None:
|
||||
raise FileNotFoundError(f"Custom skill '{name}' not found.")
|
||||
# Safety: never escape the custom root, and never remove the root itself.
|
||||
custom_root = (self._host_root / SkillCategory.CUSTOM.value).resolve()
|
||||
resolved_target = target.resolve()
|
||||
if resolved_target == custom_root or custom_root not in resolved_target.parents:
|
||||
raise ValueError(f"Refusing to delete skill '{name}': resolved path '{resolved_target}' is outside the custom skills directory.")
|
||||
if history_meta is not None:
|
||||
prev_content = self.read_custom_skill(name)
|
||||
try:
|
||||
|
||||
+1
@@ -247,6 +247,7 @@ class SkillStorage(ABC):
|
||||
extensions_config = ExtensionsConfig.from_file()
|
||||
for skill in skills:
|
||||
skill.enabled = extensions_config.is_skill_enabled(skill.name, skill.category)
|
||||
skill.always_on = extensions_config.is_skill_always_on(skill.name)
|
||||
except Exception as e:
|
||||
logger.warning("Failed to load extensions config: %s", e)
|
||||
|
||||
|
||||
Reference in new issue
Block a user