对齐 run_command 与 write_file 的默认路径行为。

将 run_command 在未传 cwd 时改为默认 data/workspace,并将 write_file 调整为相对路径写入 data/workspace、绝对路径直写(经路径守卫校验),同步更新测试与文档。

Made-with: Cursor
This commit is contained in:
oliver 2026-05-01 01:10:03 +08:00
parent d0a66d190d
commit e06184cc2f
5 changed files with 15 additions and 15 deletions

View file

@ -8,24 +8,17 @@ from oclaw.runtime.tools.path_guard import resolve_workspace_path
def write_file_tool() -> ToolSpec:
def _sandbox_base_dir() -> Path:
return Path("data") / "workspace"
def _normalize_write_path(path: str) -> str:
raw = str(path or "").strip().strip('"').strip("'")
if not raw:
raise ValueError("path_required")
p = Path(raw)
base = _sandbox_base_dir()
if p.is_absolute():
name = str(p.name or "").strip()
if not name:
raise ValueError("path_required")
return str(base / name)
return raw
rel = raw.lstrip("./\\")
if not rel:
raise ValueError("path_required")
return str(base / rel)
return str(Path("data") / "workspace" / rel)
def _handler(args: dict[str, Any]) -> dict[str, Any]:
path = str(args.get("path") or "").strip()