Skip to content

CLI-8: Make ls tool OS-agnostic with improved path handling#490

Merged
dwash96 merged 3 commits intocecli-dev:v0.99.5from
szmania:cli-8-ls-tool-os-agnostic
Apr 22, 2026
Merged

CLI-8: Make ls tool OS-agnostic with improved path handling#490
dwash96 merged 3 commits intocecli-dev:v0.99.5from
szmania:cli-8-ls-tool-os-agnostic

Conversation

@szmania
Copy link
Copy Markdown

@szmania szmania commented Apr 22, 2026

Summary

This PR updates the ls tool to be more OS-agnostic and improves path handling for better cross-platform compatibility.

Changes

  • Parameter naming: Changed from directory to path for consistency, with backward compatibility support
  • OS-agnostic paths: Replaced Unix-style path handling (startswith("/")) with os.path.abspath() and os.path.join() for cross-platform compatibility
  • Security enhancement: Added path validation to ensure resolved paths stay within the project root
  • Improved error handling: Better error messages for paths outside project root and OS-related errors
  • File vs Directory handling: Now properly handles both file and directory paths
  • Sorting: Results are now sorted alphabetically for consistent output

Technical Details

  • Uses os.path.abspath() and os.path.join() instead of manual path concatenation
  • Added security check: abs_path.startswith(os.path.abspath(coder.root))
  • Improved error handling with OSError catching for os.scandir() operations
  • Maintains backward compatibility by accepting both path and directory parameters

Testing

  • Tested on Windows with various path formats
  • Verified backward compatibility with existing code using directory parameter
  • Confirmed proper handling of both files and directories

Related

Jira: CLI-8

@dwash96 dwash96 changed the base branch from main to v0.99.5 April 22, 2026 03:21
@dwash96 dwash96 merged commit 2b08b5d into cecli-dev:v0.99.5 Apr 22, 2026
12 checks passed
@dwash96 dwash96 mentioned this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants