sync update from LAN repo (source ji @ 85078a31)

This commit is contained in:
gozeros committed 2026-10-21 15:09:16 +08:00
1 parent 5d6627af50
commit e602d88695
864 files changed
+99150 -6346

No files matched your search

@@ -4,19 +4,77 @@ from __future__ import annotations
import json
import logging
from pathlib import PurePosixPath
from typing import TYPE_CHECKING
from langchain.tools import ToolRuntime, tool
if TYPE_CHECKING:
from deerflow.skills.storage import SkillStorage
from deerflow.skills.types import Skill
logger = logging.getLogger(__name__)
_ROUNDTABLE_COORDINATOR_AGENT_ID = "roundtable-coordinator"
COORDINATOR_AGENT_IDS = frozenset(
{_ROUNDTABLE_COORDINATOR_AGENT_ID, "task-analysis-coordinator"}
)
COORDINATOR_ONLY_SKILL_NAMES = frozenset({"agent_orchestration", "agent-orchestration"})
class SkillPathUnavailableError(PermissionError):
"""Raised when a model tool targets an unknown or offline skill path."""
def require_enabled_skill_path(
path: str,
*,
container_path: str = "/mnt/skills",
storage: SkillStorage | None = None,
) -> Skill:
"""Return the discovered enabled skill containing ``path`` or deny access.
Matching uses the discovered directory instead of assuming it equals the
frontmatter name. Root/category-wide paths and unregistered files fail
closed; models discover skills through ``skill_list``/``search_skills``.
"""
normalized_container = container_path.replace("\\", "/").rstrip("/") or "/"
normalized_path = path.replace("\\", "/").rstrip("/") or "/"
if normalized_path != normalized_container and not normalized_path.startswith(f"{normalized_container}/"):
raise SkillPathUnavailableError("Path is outside the skills mount")
if ".." in PurePosixPath(normalized_path).parts:
raise SkillPathUnavailableError("Skill path traversal is not allowed")
try:
from deerflow.config.extensions_config import ExtensionsConfig
from deerflow.skills.storage import get_or_new_skill_storage
# SkillStorage intentionally degrades open on extensions-config errors;
# model-facing file access must instead fail closed.
extensions = ExtensionsConfig.from_file()
catalog = (storage or get_or_new_skill_storage()).load_skills(enabled_only=False)
except Exception as exc:
raise SkillPathUnavailableError("Skill availability could not be verified") from exc
matches: list[tuple[int, Skill]] = []
for skill in catalog:
skill_root = skill.get_container_path(normalized_container).replace("\\", "/").rstrip("/")
if normalized_path == skill_root or normalized_path.startswith(f"{skill_root}/"):
matches.append((len(skill_root), skill))
if not matches:
raise SkillPathUnavailableError("Skill path is unavailable")
skill = max(matches, key=lambda item: item[0])[1]
category = skill.category.value if hasattr(skill.category, "value") else str(skill.category)
if not extensions.is_skill_enabled(skill.name, category):
raise SkillPathUnavailableError("Skill path is unavailable")
return skill
def can_access_coordinator_only_skill(agent_id: str | None, skill_name: str) -> bool:
"""Return whether this runtime identity may discover/read a reserved orchestration skill."""
normalized = (skill_name or "").strip().lower()
return normalized not in COORDINATOR_ONLY_SKILL_NAMES or agent_id == _ROUNDTABLE_COORDINATOR_AGENT_ID
return normalized not in COORDINATOR_ONLY_SKILL_NAMES or agent_id in COORDINATOR_AGENT_IDS
def is_coordinator_only_skill_path(path: str) -> bool:
@@ -66,22 +124,31 @@ def _load_agent_skill_whitelist(agent_id: str | None, extra_skills: list[str] |
through this tool.
- Non-empty set → only these names are visible to this agent.
Exception — the deep-research collector (``deep-research-collector``) has no
whitelist: it sees every skill like the default lead agent, matching the
runtime allowlist in ``lead_agent.agent``. Its on-disk ``skills:`` entry is
ignored.
``extra_skills`` only widens the **deep-research collector** allowlist
for one run (report-structure 检索来源). Other agents ignore it.
"""
if not agent_id:
return None
try:
from deerflow.agents.deep_research.retrieval import COLLECTOR_AGENT_ID
from deerflow.config.agents_config import load_agent_config
cfg = load_agent_config(agent_id)
if cfg is None:
return None
allowed = {
name
for name in (cfg.skills or [])
if can_access_coordinator_only_skill(agent_id, name)
}
if agent_id == COLLECTOR_AGENT_ID:
allowed = None # collector: all skills, like the default lead agent
else:
allowed = {
name
for name in (cfg.skills or [])
if can_access_coordinator_only_skill(agent_id, name)
}
except Exception:
logger.debug("Failed to load agent config for skill_list filter", exc_info=True)
return None
@@ -89,8 +156,8 @@ def _load_agent_skill_whitelist(agent_id: str | None, extra_skills: list[str] |
if extra_skills:
from deerflow.agents.deep_research.retrieval import merge_collector_skill_allowlist
merged = merge_collector_skill_allowlist(agent_id, list(allowed), extra_skills)
return set(merged or [])
merged = merge_collector_skill_allowlist(agent_id, None if allowed is None else list(allowed), extra_skills)
return set(merged or []) if merged is not None else None
return allowed
@@ -169,20 +236,13 @@ def skill_view_impl(name: str, agent_id: str | None, extra_skills: list[str] | N
storage = get_or_new_skill_storage()
try:
if storage.custom_skill_exists(name):
content = storage.read_custom_skill(name)
elif storage.public_skill_exists(name):
skill_file = storage.get_skills_root_path()
from pathlib import Path
from deerflow.skills.types import SKILL_MD_FILE
path = Path(skill_file) / "public" / name / SKILL_MD_FILE
if not path.exists():
return f"Skill '{name}' not found."
content = path.read_text(encoding="utf-8")
else:
# Discover through the enabled catalog instead of reconstructing a
# path from ``name``. Besides enforcing the online/offline switch,
# this preserves skills whose directory differs from frontmatter name.
skill = next((item for item in storage.load_skills(enabled_only=True) if item.name == name), None)
if skill is None:
return f"Skill '{name}' not found."
content = skill.skill_file.read_text(encoding="utf-8")
except Exception as e:
logger.debug("skill_view failed for %r: %s", name, e)
return f"Error reading skill '{name}': {e}"
@@ -353,7 +413,7 @@ def skill_list_impl(agent_id: str | None, extra_skills: list[str] | None = None)
try:
storage = get_or_new_skill_storage()
skills = storage.load_skills(enabled_only=False)
skills = storage.load_skills(enabled_only=True)
usage = all_entries()
result = []
for skill in skills: