Update local frontend and backend changes
This commit is contained in:
1 parent
faca2c9a2d
commit
a27206c543
35 files changed
+1756
-334
No files matched your search
+113
-23
@@ -91,41 +91,48 @@ class LocalSkillStorage(SkillStorage):
|
||||
tmp_path = Path(tmp_file.name)
|
||||
tmp_path.replace(target)
|
||||
|
||||
async def ainstall_skill_from_archive(self, archive_path: str | Path) -> dict:
|
||||
def _open_skill_archive(self, archive_path: str | Path, *, require_skill_suffix: bool):
|
||||
import zipfile
|
||||
|
||||
from deerflow.skills.installer import (
|
||||
SkillAlreadyExistsError,
|
||||
_move_staged_skill_into_reserved_target,
|
||||
_scan_skill_archive_contents_or_raise,
|
||||
resolve_skill_dir_from_archive,
|
||||
safe_extract_skill_archive,
|
||||
)
|
||||
from deerflow.skills.validation import _validate_skill_frontmatter
|
||||
|
||||
logger.info("Installing skill from %s", archive_path)
|
||||
path = Path(archive_path)
|
||||
if not path.is_file():
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Skill file not found: {archive_path}")
|
||||
raise ValueError(f"Path is not a file: {archive_path}")
|
||||
if path.suffix != ".skill":
|
||||
if require_skill_suffix and path.suffix != ".skill":
|
||||
raise ValueError("File must have .skill extension")
|
||||
|
||||
custom_dir = self._host_root / "custom"
|
||||
custom_dir.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
zf = zipfile.ZipFile(path, "r")
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError(f"Skill file not found: {archive_path}") from None
|
||||
except (zipfile.BadZipFile, IsADirectoryError):
|
||||
raise ValueError("File is not a valid ZIP archive") from None
|
||||
return zf
|
||||
|
||||
def validate_skill_archive(self, archive_path: str | Path, *, require_skill_suffix: bool = False) -> dict:
|
||||
"""Inspect a skill archive WITHOUT installing it.
|
||||
|
||||
Returns a dict with ``skill_name``, ``description``, ``license``,
|
||||
``allowed_tools``, ``conflict`` (bool), ``warnings`` (list[str]).
|
||||
Raises ``ValueError`` for fatal validation problems (bad zip, bad
|
||||
frontmatter). The expensive LLM security scan is **not** invoked here.
|
||||
"""
|
||||
import re
|
||||
|
||||
import yaml
|
||||
|
||||
from deerflow.skills.installer import (
|
||||
resolve_skill_dir_from_archive,
|
||||
safe_extract_skill_archive,
|
||||
)
|
||||
from deerflow.skills.types import SKILL_MD_FILE
|
||||
from deerflow.skills.validation import _validate_skill_frontmatter
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
|
||||
try:
|
||||
zf = zipfile.ZipFile(path, "r")
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError(f"Skill file not found: {archive_path}") from None
|
||||
except (zipfile.BadZipFile, IsADirectoryError):
|
||||
raise ValueError("File is not a valid ZIP archive") from None
|
||||
|
||||
with zf:
|
||||
with self._open_skill_archive(archive_path, require_skill_suffix=require_skill_suffix) as zf:
|
||||
safe_extract_skill_archive(zf, tmp_path)
|
||||
|
||||
skill_dir = resolve_skill_dir_from_archive(tmp_path)
|
||||
@@ -136,9 +143,91 @@ class LocalSkillStorage(SkillStorage):
|
||||
if not skill_name or "/" in skill_name or "\\" in skill_name or ".." in skill_name:
|
||||
raise ValueError(f"Invalid skill name: {skill_name}")
|
||||
|
||||
skill_md_text = (skill_dir / SKILL_MD_FILE).read_text(encoding="utf-8")
|
||||
frontmatter: dict = {}
|
||||
match = re.match(r"^---\n(.*?)\n---", skill_md_text, re.DOTALL)
|
||||
if match:
|
||||
try:
|
||||
parsed = yaml.safe_load(match.group(1)) or {}
|
||||
if isinstance(parsed, dict):
|
||||
frontmatter = parsed
|
||||
except yaml.YAMLError:
|
||||
frontmatter = {}
|
||||
|
||||
allowed_tools = frontmatter.get("allowed-tools") or []
|
||||
if not isinstance(allowed_tools, list):
|
||||
allowed_tools = [str(allowed_tools)]
|
||||
else:
|
||||
allowed_tools = [str(item) for item in allowed_tools]
|
||||
|
||||
warnings: list[str] = []
|
||||
script_files = [
|
||||
path for path in skill_dir.rglob("*")
|
||||
if path.is_file() and path.relative_to(skill_dir).parts and path.relative_to(skill_dir).parts[0] == "scripts"
|
||||
]
|
||||
if script_files:
|
||||
warnings.append(f"Archive contains {len(script_files)} script file(s); they will be security-scanned at install time.")
|
||||
|
||||
conflict_custom = (self._host_root / SkillCategory.CUSTOM.value / skill_name / SKILL_MD_FILE).exists()
|
||||
conflict_public = self.public_skill_exists(skill_name)
|
||||
conflict = conflict_custom or conflict_public
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"skill_name": skill_name,
|
||||
"description": str(frontmatter.get("description", "")).strip(),
|
||||
"license": (str(frontmatter["license"]).strip() if frontmatter.get("license") else None),
|
||||
"allowed_tools": allowed_tools,
|
||||
"conflict": conflict,
|
||||
"conflict_kind": ("public" if conflict_public else ("custom" if conflict_custom else None)),
|
||||
"warnings": warnings,
|
||||
}
|
||||
|
||||
async def ainstall_skill_from_archive(
|
||||
self,
|
||||
archive_path: str | Path,
|
||||
*,
|
||||
overwrite: bool = False,
|
||||
require_skill_suffix: bool = True,
|
||||
) -> dict:
|
||||
from deerflow.skills.installer import (
|
||||
SkillAlreadyExistsError,
|
||||
_move_staged_skill_into_reserved_target,
|
||||
_scan_skill_archive_contents_or_raise,
|
||||
resolve_skill_dir_from_archive,
|
||||
safe_extract_skill_archive,
|
||||
)
|
||||
from deerflow.skills.validation import _validate_skill_frontmatter
|
||||
|
||||
logger.info("Installing skill from %s (overwrite=%s)", archive_path, overwrite)
|
||||
|
||||
custom_dir = self._host_root / "custom"
|
||||
custom_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
|
||||
with self._open_skill_archive(archive_path, require_skill_suffix=require_skill_suffix) as zf:
|
||||
safe_extract_skill_archive(zf, tmp_path)
|
||||
|
||||
skill_dir = resolve_skill_dir_from_archive(tmp_path)
|
||||
|
||||
is_valid, message, skill_name = _validate_skill_frontmatter(skill_dir)
|
||||
if not is_valid:
|
||||
raise ValueError(f"Invalid skill: {message}")
|
||||
if not skill_name or "/" in skill_name or "\\" in skill_name or ".." in skill_name:
|
||||
raise ValueError(f"Invalid skill name: {skill_name}")
|
||||
|
||||
if self.public_skill_exists(skill_name):
|
||||
raise SkillAlreadyExistsError(f"Skill '{skill_name}' conflicts with a built-in public skill and cannot be overwritten")
|
||||
|
||||
target = custom_dir / skill_name
|
||||
replaced = False
|
||||
if target.exists():
|
||||
raise SkillAlreadyExistsError(f"Skill '{skill_name}' already exists")
|
||||
if not overwrite:
|
||||
raise SkillAlreadyExistsError(f"Skill '{skill_name}' already exists")
|
||||
shutil.rmtree(target)
|
||||
replaced = True
|
||||
|
||||
await _scan_skill_archive_contents_or_raise(skill_dir, skill_name)
|
||||
|
||||
@@ -152,6 +241,7 @@ class LocalSkillStorage(SkillStorage):
|
||||
"success": True,
|
||||
"skill_name": skill_name,
|
||||
"message": f"Skill '{skill_name}' installed successfully",
|
||||
"overwritten": replaced,
|
||||
}
|
||||
|
||||
def delete_custom_skill(self, name: str, *, history_meta: dict | None = None) -> None:
|
||||
|
||||
Reference in new issue
Block a user