Skip to content

[BUG] list_dir returns "invalid argument" on Windows due to path separator mismatch with os.Root #2472

@ut2or1

Description

@ut2or1

Quick Summary

list_dir fails on Windows with invalid argument because platform-specific backslashes (\) are passed directly to Go's fs.FS/os.Root, which strictly requires forward slashes (/).

Environment & Tools

  • PicoClaw Version: 0.2.6
  • Go Version: 1.26
  • AI Model & Provider: any
  • Operating System: Windows 11
  • Channels: WebUI

📸 Steps to Reproduce

  1. Configure Picoclaw with restrict_to_workspace: true and a valid workspace directory.
  2. Call the list_dir tool with a relative path containing a trailing slash: {"path": "src/Sources/"}.
  3. Observe the tool's response.

❌ Actual Behavior

Returns an invalid argument error. Directory listing fails completely, even though the path exists, is within the workspace, and works correctly via exec {"action":"run","command":"dir src\\Sources"}.

✅ Expected Behavior

Successfully returns the file/directory listing for src/Sources/ without errors, consistent with standard Windows path handling.

💬 Additional Context

Root Cause: filepath.Clean() and filepath.Rel() produce Windows backslashes (\). These are passed directly to fs.ReadDir(root.FS(), relPath) and root.Open(relPath). Go's fs.FS interface strictly expects forward slashes (/) on all platforms, causing invalid argument on Windows.

Proposed Fix (pkg/tools/filesystem.go):
Convert the relative path using filepath.ToSlash() before any fs.FS call:

// In sandboxFs.ReadDir & sandboxFs.Open
fsPath := filepath.ToSlash(relPath)
// Pass fsPath to fs.ReadDir(root.FS(), fsPath) and root.Open(fsPath)

Note: This forward/backslash separator mismatch likely affects other file operations (read_file, write_file, move_file, etc.) that rely on the same sandboxFs implementation. A broader review of all fs.FS/os.Root interactions across the codebase is recommended to prevent similar cross-platform edge cases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions