Skip to content

Commit 13c8fa3

Browse files
committed
fix(skills): use workspace path for sandbox skills
default sandbox skill paths to /workspace/skills/<name>/SKILL.md when loading config and when exposing sandbox paths. preserve cached sandbox paths when available to avoid losing resolved locations for existing skills.
1 parent 4ff4c5f commit 13c8fa3

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

astrbot/core/skills/skill_manager.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
SANDBOX_SKILLS_CACHE_FILENAME = "sandbox_skills_cache.json"
2121
DEFAULT_SKILLS_CONFIG: dict[str, dict] = {"skills": {}}
2222
SANDBOX_SKILLS_ROOT = "skills"
23+
SANDBOX_WORKSPACE_ROOT = "/workspace"
2324
_SANDBOX_SKILLS_CACHE_VERSION = 1
2425

2526
_SKILL_NAME_RE = re.compile(r"^[A-Za-z0-9._-]+$")
@@ -185,7 +186,7 @@ def set_sandbox_skills_cache(self, skills: list[dict]) -> None:
185186
description = str(item.get("description", "") or "")
186187
path = str(item.get("path", "") or "")
187188
if not path:
188-
path = f"{SANDBOX_SKILLS_ROOT}/{name}/SKILL.md"
189+
path = f"{SANDBOX_WORKSPACE_ROOT}/{SANDBOX_SKILLS_ROOT}/{name}/SKILL.md"
189190
deduped[name] = {
190191
"name": name,
191192
"description": description,
@@ -215,6 +216,17 @@ def list_skills(
215216
modified = False
216217
skills_by_name: dict[str, SkillInfo] = {}
217218

219+
sandbox_cached_paths: dict[str, str] = {}
220+
if runtime == "sandbox":
221+
cache_for_paths = self._load_sandbox_skills_cache()
222+
for item in cache_for_paths.get("skills", []):
223+
if not isinstance(item, dict):
224+
continue
225+
name = str(item.get("name", "") or "").strip()
226+
path = str(item.get("path", "") or "").strip().replace("\\", "/")
227+
if name and path and _SKILL_NAME_RE.match(name):
228+
sandbox_cached_paths[name] = path
229+
218230
for entry in sorted(Path(self.skills_root).iterdir()):
219231
if not entry.is_dir():
220232
continue
@@ -235,7 +247,9 @@ def list_skills(
235247
except Exception:
236248
description = ""
237249
if runtime == "sandbox" and show_sandbox_path:
238-
path_str = f"{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
250+
path_str = sandbox_cached_paths.get(skill_name) or (
251+
f"{SANDBOX_WORKSPACE_ROOT}/{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
252+
)
239253
else:
240254
path_str = str(skill_md)
241255
path_str = path_str.replace("\\", "/")
@@ -266,11 +280,15 @@ def list_skills(
266280
continue
267281
description = str(item.get("description", "") or "")
268282
if show_sandbox_path:
269-
path_str = f"{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
283+
path_str = (
284+
f"{SANDBOX_WORKSPACE_ROOT}/{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
285+
)
270286
else:
271287
path_str = str(item.get("path", "") or "")
272288
if not path_str:
273-
path_str = f"{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
289+
path_str = (
290+
f"{SANDBOX_WORKSPACE_ROOT}/{SANDBOX_SKILLS_ROOT}/{skill_name}/SKILL.md"
291+
)
274292
skills_by_name[skill_name] = SkillInfo(
275293
name=skill_name,
276294
description=description,

0 commit comments

Comments
 (0)