fix(computer): resolve absolute skill paths at runtime in scan command

- Resolve skills root via Path.resolve() so LLM prompts always
  reference absolute paths regardless of sandbox cwd
- Use resolved path in skill metadata for reliable cat/head commands
- Add DRY cross-reference comment for frontmatter parser
- Remove dead skills_root_abs field from JSON output (no consumer)
- Remove unnecessary os import and fake resolve/abspath branch
This commit is contained in:
zenfun
2026-02-21 01:03:45 +08:00
parent b816045f37
commit c1917ebf4f
+10 -1
View File
@@ -183,6 +183,10 @@ def _build_scan_command() -> str:
This stage is read-oriented: it scans SKILL.md metadata and returns the
historical payload shape consumed by cache update logic.
The scan resolves the absolute path of the skills root at runtime so
that the LLM can reliably ``cat`` skill files regardless of cwd.
Only the ``description`` field is extracted from frontmatter.
"""
script = f"""
import json
@@ -191,7 +195,12 @@ from pathlib import Path
root = Path({SANDBOX_SKILLS_ROOT!r})
managed_file = root / {_MANAGED_SKILLS_FILE!r}
# Resolve absolute path at runtime so prompts always have a reliable path
root_abs = str(root.resolve())
# NOTE: This parser mirrors skill_manager._parse_frontmatter_description.
# Keep the two implementations in sync when changing parsing logic.
def parse_description(text: str) -> str:
if not text.startswith("---"):
return ""
@@ -253,7 +262,7 @@ def collect_skills() -> list[dict[str, str]]:
{{
"name": skill_dir.name,
"description": description,
"path": f"{SANDBOX_SKILLS_ROOT}/{{skill_dir.name}}/SKILL.md",
"path": f"{{root_abs}}/{{skill_dir.name}}/SKILL.md",
}}
)
return skills