Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(filesystem): normalize caller paths to deepagents virtual form
trohitg42bd078652d3
diff --git a/server/nodes/filesystem/_backend.py b/server/nodes/filesystem/_backend.pyindex e6d1419b..79e540fb 100644--- a/server/nodes/filesystem/_backend.py+++ b/server/nodes/filesystem/_backend.py@@ -9,8 +9,38 @@ setup so each plugin file stays small.from __future__ import annotationsimport os+from pathlib import PureWindowsPathfrom typing import Any, Dict, Optional+from deepagents.backends.utils import validate_path+++def normalize_virtual_path(path: str) -> str:+ """Coerce any caller-supplied path to deepagents' canonical virtual form.++ LLMs (and humans) emit paths in every flavour: ``/foo`` (POSIX),+ ``C:\\foo`` (Windows drive), ``\\\\server\\share\\foo`` (UNC),+ ``foo\\bar`` / ``foo/bar`` (relative, mixed separators). deepagents'+ ``virtual_mode`` only resolves POSIX virtual paths, and its public+ :func:`validate_path` helper rejects Windows-anchored inputs.++ ``PureWindowsPath`` is a pure (host-OS independent) parser and is a+ superset of the POSIX grammar — Windows itself accepts ``/`` as a+ separator, so ``PureWindowsPath('/tmp/foo')`` correctly identifies+ ``/`` as the root anchor. That means a single parser covers Windows+ drives, UNC, and POSIX absolutes uniformly on any host OS. Strip+ the anchor here, then delegate to :func:`validate_path` for traversal+ rejection (``..``, ``~``) and canonical normalisation.+ """+ if not path:+ return path+ pw = PureWindowsPath(path)+ if pw.drive or pw.root:+ rel = "/" + "/".join(pw.parts[1:]) if len(pw.parts) > 1 else "/"+ else:+ rel = path.replace("\\", "/")+ return validate_path(rel)+def get_backend(parameters: Dict[str, Any],diff --git a/server/nodes/filesystem/file_modify.py b/server/nodes/filesystem/file_modify.pyindex 4b2b3719..fb9ed252 100644--- a/server/nodes/filesystem/file_modify.py+++ b/server/nodes/filesystem/file_modify.py@@ -53,30 +53,48 @@ class FileModifyNode(ActionNode):async def modify(self, ctx: NodeContext, params: FileModifyParams) -> Any:"""Inlined from handlers/filesystem.py (Wave 11.D.1)."""import asyncio- from ._backend import get_backend+ from ._backend import get_backend, normalize_virtual_pathif not params.file_path:raise RuntimeError("file_path is required")backend = get_backend(params.model_dump(), ctx.raw)+ file_path = normalize_virtual_path(params.file_path)if params.operation == "write":- result = await asyncio.to_thread(backend.write, params.file_path, params.content)+ # ``write`` is wholesale create-or-replace. deepagents'+ # backend.write() refuses to overwrite by design, so unlink any+ # pre-existing file at the resolved path first; ``edit`` remains+ # the surgical option for callers that want a partial change.+ def _do_write():+ resolved = backend._resolve_path(file_path)+ if resolved.exists():+ if resolved.is_dir():+ raise IsADirectoryError(+ f"Cannot write to {file_path}: path is a directory"+ )+ resolved.unlink()+ return backend.write(file_path, params.content)++ try:+ result = await asyncio.to_thread(_do_write)+ except (OSError, ValueError) as e:+ raise RuntimeError(str(e)) from eif result.error:raise RuntimeError(result.error)- return {"operation": "write", "file_path": result.path or params.file_path}+ return {"operation": "write", "file_path": result.path or file_path}if params.operation == "edit":if not params.old_string:raise RuntimeError("old_string is required for edit")result = await asyncio.to_thread(- backend.edit, params.file_path, params.old_string, params.new_string,+ backend.edit, file_path, params.old_string, params.new_string,replace_all=params.replace_all,)if result.error:raise RuntimeError(result.error)return {"operation": "edit",- "file_path": result.path or params.file_path,+ "file_path": result.path or file_path,"occurrences": result.occurrences,}diff --git a/server/nodes/filesystem/file_read.py b/server/nodes/filesystem/file_read.pyindex ce947fda..6da7e8ce 100644--- a/server/nodes/filesystem/file_read.py+++ b/server/nodes/filesystem/file_read.py@@ -46,13 +46,14 @@ class FileReadNode(ActionNode):async def read(self, ctx: NodeContext, params: FileReadParams) -> Any:"""Inlined from handlers/filesystem.py (Wave 11.D.1)."""import asyncio- from ._backend import get_backend+ from ._backend import get_backend, normalize_virtual_pathif not params.file_path:raise RuntimeError("file_path is required")backend = get_backend(params.model_dump(), ctx.raw)+ file_path = normalize_virtual_path(params.file_path)content = await asyncio.to_thread(- backend.read, params.file_path,+ backend.read, file_path,offset=params.offset, limit=params.limit,)- return {"content": content, "file_path": params.file_path}+ return {"content": content, "file_path": file_path}diff --git a/server/nodes/filesystem/fs_search.py b/server/nodes/filesystem/fs_search.pyindex 3e34c65b..19c4cc58 100644--- a/server/nodes/filesystem/fs_search.py+++ b/server/nodes/filesystem/fs_search.py@@ -46,14 +46,15 @@ class FsSearchNode(ActionNode):async def search(self, ctx: NodeContext, params: FsSearchParams) -> Any:"""Inlined from handlers/filesystem.py (Wave 11.D.1)."""import asyncio- from ._backend import get_backend+ from ._backend import get_backend, normalize_virtual_pathbackend = get_backend(params.model_dump(), ctx.raw)+ path = normalize_virtual_path(params.path)if params.mode == "ls":- entries = await asyncio.to_thread(backend.ls_info, params.path)+ entries = await asyncio.to_thread(backend.ls_info, path)return {- "path": params.path,+ "path": path,"entries": [dict(e) for e in entries],"count": len(entries),}@@ -62,10 +63,10 @@ class FsSearchNode(ActionNode):if not params.pattern:raise RuntimeError("pattern is required for glob mode")matches = await asyncio.to_thread(- backend.glob_info, params.pattern, path=params.path,+ backend.glob_info, params.pattern, path=path,)return {- "path": params.path,+ "path": path,"pattern": params.pattern,"matches": [dict(m) for m in matches],"count": len(matches),@@ -75,12 +76,12 @@ class FsSearchNode(ActionNode):if not params.pattern:raise RuntimeError("pattern is required for grep mode")result = await asyncio.to_thread(- backend.grep_raw, params.pattern, path=params.path,+ backend.grep_raw, params.pattern, path=path,)if isinstance(result, str):raise RuntimeError(result)return {- "path": params.path,+ "path": path,"pattern": params.pattern,"matches": [dict(m) for m in result],"count": len(result),diff --git a/server/skills/coding_agent/file-modify-skill/SKILL.md b/server/skills/coding_agent/file-modify-skill/SKILL.mdindex 261b0741..01a3ba84 100644--- a/server/skills/coding_agent/file-modify-skill/SKILL.md+++ b/server/skills/coding_agent/file-modify-skill/SKILL.md@@ -19,9 +19,9 @@ Write new files or edit existing files with exact string replacement. Uses deepa| Field | Type | Required | Description ||-------|------|----------|-------------|-| operation | string | Yes | `write` (create/overwrite) or `edit` (find and replace) |+| operation | string | Yes | `write` (create or wholesale-replace the file) or `edit` (surgical find-and-replace inside an existing file) || file_path | string | Yes | Path to the file |-| content | string | If write | Full file content to write |+| content | string | If write | Full file content to write — overwrites any existing file at this path || old_string | string | If edit | Exact text to find and replace || new_string | string | If edit | Replacement text || replace_all | boolean | No | Replace all occurrences (default: false, old_string must be unique) |@@ -72,8 +72,8 @@ Write new files or edit existing files with exact string replacement. Uses deepa### Guidelines-1. Use `write` to create new files or overwrite existing ones-2. Use `edit` for surgical string replacement in existing files-3. For edit: `old_string` must be unique in the file unless `replace_all` is true-4. Prefer `edit` over `write` when modifying existing files-5. Read the file first before editing to ensure correct context+1. Use `write` to create a new file or replace an existing file's contents wholesale. Provide the full new contents in `content`; any existing file at `file_path` is replaced.+2. Use `edit` for surgical string replacement inside an existing file — it is the right choice when you want to change a small portion of a file rather than rewrite the whole thing.+3. For edit: `old_string` must be unique in the file unless `replace_all` is true.+4. Prefer `edit` over `write` when changing only part of an existing file — it produces a smaller diff and is less destructive.+5. Read the file first before editing to ensure correct context.