Skip to content

Create, Evaluate, and Connect AI Skills

fix: Windows compatibility for skill evaluation and Codex routing

应飞扬f4c82c4dea77
diff --git a/skillnet-ai/src/skillnet_ai/evaluator.py b/skillnet-ai/src/skillnet_ai/evaluator.py
index 40c5693..f19f1f7 100644
--- a/skillnet-ai/src/skillnet_ai/evaluator.py
+++ b/skillnet-ai/src/skillnet_ai/evaluator.py
@@ -592,7 +592,7 @@ class SkillLoader:
def record_walk_error(error: OSError) -> None:
failed_path = error.filename or skill_dir
- rel_path = os.path.relpath(failed_path, skill_dir)
+ rel_path = os.path.relpath(failed_path, skill_dir).replace(os.sep, "/")
SkillLoader._record_scan_issue(
scan_issues,
rel_path,
@@ -602,7 +602,7 @@ class SkillLoader:
for root, dirs, files in os.walk(skill_dir, onerror=record_walk_error):
entries_seen += len(dirs) + len(files)
if entries_seen > SkillLoader.MAX_WALK_ENTRIES:
- rel_root = os.path.relpath(root, skill_dir)
+ rel_root = os.path.relpath(root, skill_dir).replace(os.sep, "/")
SkillLoader._record_scan_issue(
scan_issues,
rel_root,
@@ -643,7 +643,7 @@ class SkillLoader:
if not file_filter(filename):
continue
filepath = os.path.join(root, filename)
- rel_path = os.path.relpath(filepath, skill_dir)
+ rel_path = os.path.relpath(filepath, skill_dir).replace(os.sep, "/")
if len(items) >= max_files:
SkillLoader._record_scan_issue(
scan_issues,
@@ -689,7 +689,7 @@ class SkillLoader:
)
return None
- rel_path = os.path.relpath(path, skill_dir)
+ rel_path = os.path.relpath(path, skill_dir).replace(os.sep, "/")
try:
with open(path, "r", encoding="utf-8") as f:
content = f.read(max_chars + 1)
diff --git a/skillnet-ai/src/skillnet_ai/router/explorer.py b/skillnet-ai/src/skillnet_ai/router/explorer.py
index e7bb79c..5bea7f2 100644
--- a/skillnet-ai/src/skillnet_ai/router/explorer.py
+++ b/skillnet-ai/src/skillnet_ai/router/explorer.py
@@ -5,6 +5,8 @@ SDK setup adapted from SkillFabric; Copyright (c) 2026 SkillFabric Contributors,
import asyncio
import logging
+import re
+import sys
import threading
from collections import Counter
from collections.abc import AsyncGenerator, AsyncIterator
@@ -25,6 +27,12 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
PATH_KEYS = {"Read": "file_path", "Glob": "path", "Grep": "path", "LS": "path"}
+POWERSHELL_UTF8_PREFIX = "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\n"
+WINDOWS_EXPLORER_TOOLS = (
+ "\nUse noninteractive exec_command only: Get-ChildItem -LiteralPath '<path>' -Name "
+ "or Get-Content -LiteralPath '<path>' -Encoding UTF8. Use single-quoted relative Wiki "
+ "paths. No other arguments, scripts, interactive sessions, network or skill execution."
+)
class ClaudeExplorer:
@@ -149,9 +157,20 @@ def validate_wiki_command(item: dict[str, Any], root: Path) -> None:
if not actions:
raise ValueError("Codex command has no recognized read/search action.")
for action in actions:
- if action["type"] not in {"read", "listFiles", "search"}:
- raise ValueError("Codex Explorer supports only file reads and searches.")
value = action.get("path")
+ if sys.platform == "win32" and action["type"] == "unknown":
+ command = action.get("command", "").removeprefix(POWERSHELL_UTF8_PREFIX).strip()
+ match = re.fullmatch(
+ r"Get-Content -LiteralPath '((?!~)[^'\r\n:]+)' -Encoding UTF8"
+ r"|Get-ChildItem -LiteralPath '((?!~)[^'\r\n:]+)' -Name",
+ command,
+ flags=re.IGNORECASE,
+ )
+ if match is None:
+ raise ValueError("Codex Explorer supports only literal PowerShell reads/listings.")
+ value = match[1] or match[2]
+ elif action["type"] not in {"read", "listFiles", "search"}:
+ raise ValueError("Codex Explorer supports only file reads and searches.")
if value is None:
continue
path = (cwd / value).resolve()
@@ -183,7 +202,11 @@ class CodexExplorer:
"CODEX_API_KEY": "",
"CODEX_ACCESS_TOKEN": "",
},
- config_overrides=("check_for_update_on_startup=false",),
+ config_overrides=(
+ "check_for_update_on_startup=false",
+ "features.plugins=false",
+ "features.remote_plugin=false",
+ ),
)
client = sdk.Codex(config=config)
expired = threading.Event()
@@ -209,7 +232,8 @@ class CodexExplorer:
ephemeral=True,
approval_mode=sdk.ApprovalMode.deny_all,
sandbox=sdk.Sandbox.read_only,
- developer_instructions=explorer_prompt(k, read_limit) + CODEX_EXPLORER_TOOLS,
+ developer_instructions=explorer_prompt(k, read_limit)
+ + (WINDOWS_EXPLORER_TOOLS if sys.platform == "win32" else CODEX_EXPLORER_TOOLS),
config={
"openai_base_url": endpoint.base_url,
"web_search": "disabled",
diff --git a/skillnet-ai/tests/test_evaluator_injection_boundary.py b/skillnet-ai/tests/test_evaluator_injection_boundary.py
index 0c660bc..b94022a 100644
--- a/skillnet-ai/tests/test_evaluator_injection_boundary.py
+++ b/skillnet-ai/tests/test_evaluator_injection_boundary.py
@@ -415,7 +415,7 @@ def test_evaluator_reports_reference_file_limit_as_incomplete(tmp_path, monkeypa
def test_loader_reports_directory_walk_failure(tmp_path, monkeypatch):
- failed_path = tmp_path / "references"
+ failed_path = tmp_path / "references" / "nested"
def fail_walk(_path, onerror=None):
if onerror is not None:
@@ -432,7 +432,7 @@ def test_loader_reports_directory_walk_failure(tmp_path, monkeypatch):
)
assert references == []
- assert issues[0].file == "references"
+ assert issues[0].file == "references/nested"
assert "directory" in issues[0].reason.lower()
@@ -472,7 +472,7 @@ def test_loader_does_not_find_skill_md_in_ignored_directory(tmp_path):
def test_loader_bounds_directory_entries(tmp_path, monkeypatch):
def large_walk(_path, onerror=None):
del onerror
- yield str(tmp_path), [f"dir-{index}" for index in range(10_001)], []
+ yield str(tmp_path / "nested" / "references"), [f"dir-{index}" for index in range(10_001)], []
monkeypatch.setattr(evaluator_module.os, "walk", large_walk)
issues = []
@@ -482,6 +482,7 @@ def test_loader_bounds_directory_entries(tmp_path, monkeypatch):
)
assert references == []
+ assert issues[0].file == "nested/references"
assert "entry limit" in issues[0].reason.lower()
diff --git a/skillnet-ai/tests/test_route.py b/skillnet-ai/tests/test_route.py
index daf3cf6..68c0e2c 100644
--- a/skillnet-ai/tests/test_route.py
+++ b/skillnet-ai/tests/test_route.py
@@ -5,6 +5,7 @@ import json
import sys
import threading
from collections.abc import AsyncIterator, Iterator
+from contextlib import nullcontext
from pathlib import Path
from types import ModuleType, SimpleNamespace
@@ -23,6 +24,7 @@ from skillnet_ai.core.models import (
SkillSelection,
)
from skillnet_ai.interfaces.cli import app
+from skillnet_ai.router import explorer as explorer_module
from skillnet_ai.router.explorer import ClaudeExplorer, CodexExplorer
ENDPOINT = Endpoint(api_key=SecretStr("test-key"), base_url="https://model.test/v1", model="test")
@@ -245,7 +247,7 @@ def test_claude_session(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, timeout
assert closed.is_set()
[email protected]("failure", [None, "provider", "timeout", "outside", "tool"])
[email protected]("failure", [None, "provider", "timeout", "outside", "tool", "windows"])
def test_codex_session(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, failure: str | None
) -> None:
@@ -257,6 +259,8 @@ def test_codex_session(
SimpleNamespace(read_only="read-only"),
)
closed = threading.Event()
+ if failure == "windows":
+ monkeypatch.setattr(explorer_module, "sys", SimpleNamespace(platform="win32"))
def event(method: str, payload: dict[str, object]) -> SimpleNamespace:
return SimpleNamespace(method=method, payload=RootModel[dict](payload))
@@ -274,11 +278,16 @@ def test_codex_session(
"exitCode": None,
"commandActions": [
{
- "type": "unknown" if failure == "tool" else "search",
+ "type": "unknown" if failure in {"tool", "windows"} else "search",
"path": "../outside" if failure == "outside" else "sources/stats.md",
+ "command": "python -V",
}
],
}
+ if failure == "windows":
+ item["commandActions"][0]["command"] = explorer_module.POWERSHELL_UTF8_PREFIX + (
+ "Get-Content -LiteralPath 'sources/stats.md' -Encoding UTF8"
+ )
yield event("item/started", {"item": item})
yield event("item/completed", {"item": {**item, "exitCode": 0}})
yield event(
@@ -296,6 +305,10 @@ def test_codex_session(
class Codex:
def __init__(self, *, config: SimpleNamespace) -> None:
assert config.env["OPENAI_API_KEY"] == "test-key"
+ assert {
+ "features.plugins=false",
+ "features.remote_plugin=false",
+ } <= set(config.config_overrides)
def __enter__(self) -> "Codex":
return self
@@ -324,7 +337,7 @@ def test_codex_session(
monkeypatch.setitem(sys.modules, "openai_codex", sdk)
monkeypatch.setitem(sys.modules, "openai_codex.types", types)
options = RouteOptions(timeout=0.05 if failure == "timeout" else 300)
- if failure:
+ if failure and failure != "windows":
error = {
"provider": RuntimeError,
"timeout": TimeoutError,
@@ -337,3 +350,25 @@ def test_codex_session(
result = CodexExplorer().explore(tmp_path, "task", 1, ENDPOINT, options)
assert result.selection == selection()
assert closed.is_set()
+
+
[email protected]("platform", ["win32", "linux", "darwin"])
+ ("command", "allowed"),
+ [
+ ("Get-Content -LiteralPath 'sources/stats notes.md' -Encoding UTF8", True),
+ ("Get-ChildItem -LiteralPath '.' -Name", True),
+ ("Get-Content -LiteralPath '../outside.md' -Encoding UTF8", False),
+ ("Get-Content -LiteralPath 'Env:OPENAI_API_KEY' -Encoding UTF8", False),
+ ("Get-Content -LiteralPath '~/outside.md' -Encoding UTF8", False),
+ ("Get-ChildItem -LiteralPath '.' -Name; Remove-Item 'index.md'", False),
+ ("Get-Content -LiteralPath 'index.md' -Encoding UTF8 | Invoke-Expression", False),
+ ],
+)
+def test_powershell_wiki_commands(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, platform: str, command: str, allowed: bool
+) -> None:
+ monkeypatch.setattr(explorer_module, "sys", SimpleNamespace(platform=platform))
+ item = {"cwd": str(tmp_path), "commandActions": [{"type": "unknown", "command": command}]}
+ with nullcontext() if allowed and platform == "win32" else pytest.raises(ValueError):
+ explorer_module.validate_wiki_command(item, tmp_path)