Fix Windows Path Handling in Filesystem Operations #336
+41
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Windows Path Handling in Filesystem Operations
Summary
This PR fixes Windows path handling issues in the filesystem backend and middleware that prevented proper file operations on Windows systems. **Fixes #340 **
Problem
The codebase had multiple issues with Windows path handling:
Path Validation Issue: The
_validate_path()function in middleware incorrectly added a leading slash to Windows absolute paths (e.g.,C:/Users/...became/C:/Users/...), breaking path resolution in the backend.Inconsistent Path Separators: The
FilesystemBackend.ls_info()method mixed Windows backslashes and POSIX forward slashes, causing test failures and inconsistent behavior (e.g., returning/\local.txtinstead of/local.txt).Reproduction Steps
This procedure demonstrates the incorrect path handling on Windows:
9ed6483e...) and run the application:ls(.)We might need to add an exception handler for
ModuleNotFoundError: No module named 'termios'within execution.py to ensure successful startup of deepagents on Windows environments. This module is typically Unix-specific, and catching the exception would allow the program to gracefully proceed without terminal control featuresRoot Cause
When an AI agent called
ls("C:\..."):_validate_path()normalized it to/C:/...(added leading/)FilesystemBackend._resolve_path()treated this as a relative pathIn
backends/filesystem.py: ls_infoAdditionally, the backend's
ls_info()returned paths with mixed separators on Windows, breaking cross-platform compatibility.Solution
1. Improved Windows Path Detection (
middleware/filesystem.py)Before:
After:
Benefits:
C:,D:)\\server\share)2. Consistent POSIX-Style Path Normalization (
backends/filesystem.py)Updated
ls_info(),grep_raw(), andglob_info()to consistently normalize all returned paths to POSIX style (forward slashes only):Benefits:
3. Updated Tests for Cross-Platform Compatibility
Modified test assertions to normalize paths before comparison:
Unit Tests on Windows
Before Fix
After Fix