Skip to content

fix: convert rtk ls from reimplementation to native proxy#38

Merged
pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/ls-native-proxy
Feb 1, 2026
Merged

fix: convert rtk ls from reimplementation to native proxy#38
pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/ls-native-proxy

Conversation

@FlorianBruniaux

Copy link
Copy Markdown
Collaborator

Summary

  • Converts rtk ls from a WalkBuilder reimplementation to a native ls proxy
  • Now supports all native ls flags: -l, -a, -h, -R, etc.
  • Default behavior: -la when no args provided
  • Token optimization: filters "total X" line from output

Problem

rtk ls -al failed because -l was not a recognized flag. The previous implementation reimplemented directory traversal instead of proxying to native ls, which is inconsistent with rtk's philosophy (proxy and filter, don't reimplement).

Breaking Changes

Removes the following flags:

  • --depth / -d
  • --format (tree/flat/json)
  • --all / -a (replaced by native -a)

These are replaced by native ls flags.

Test Plan

  • rtk ls -la works
  • rtk ls -alh works
  • rtk ls defaults to -la
  • rtk ls -R src/ works (recursive)
  • "total X" line is filtered
  • Exit code preserved on error
  • Unit tests pass

🤖 Generated with Claude Code

BREAKING CHANGE: Removes --depth, --format (tree/flat/json) flags

Before: `rtk ls` was a reimplementation using WalkBuilder that didn't
support native ls flags like -l, -a, -h, -R.

After: `rtk ls` proxies to native ls, supporting all flags:
- `rtk ls -la` works
- `rtk ls -alh` works
- `rtk ls -R src/` works
- Default: `-la` when no args

Token optimization: filters "total X" line from output.

This aligns with rtk philosophy: proxy and filter, don't reimplement.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 1, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Converts rtk ls from a custom directory traversal implementation to a native ls proxy while applying minimal output filtering for token savings.

Changes:

  • Replaces rtk ls’s custom traversal/formatting with a direct ls subprocess call.
  • Updates CLI parsing for rtk ls to pass through arbitrary ls flags/args and default to -la when none are provided.
  • Adds unit tests for the ls output filter (removing total X lines).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/main.rs Updates rtk ls CLI interface and wires the subcommand to the new ls::run(&args, verbose) signature.
src/ls.rs Implements native ls proxy execution, filters output, adds verbose reduction stats, and introduces filter-focused tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ls.rs
Comment on lines +11 to +16
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let mut cmd = Command::new("ls");

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"tree" => Ok(OutputFormat::Tree),
"flat" => Ok(OutputFormat::Flat),
"json" => Ok(OutputFormat::Json),
_ => Err(format!("Unknown format: {}", s)),
// Default to -la if no args (common case for LLM context)
if args.is_empty() {
cmd.args(["-la"]);

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command::new("ls") will fail on Windows, but the project docs explicitly claim cross-platform support (e.g., ARCHITECTURE.md notes macOS/Linux/Windows). Add a Windows implementation (e.g., proxy to cmd /C dir or PowerShell Get-ChildItem, with equivalent filtering), or gracefully fall back when ls isn't available and return a clear error.

Copilot uses AI. Check for mistakes.
Comment thread src/ls.rs
Comment on lines +23 to 29
let output = cmd.output().context("Failed to run ls")?;

// Skip the root itself
if entry_path == path {
continue;
}

let depth = entry_path.components().count() - base_depth;
let name = entry_path
.file_name()
.map(|n| n.to_string_lossy().to_string())
.unwrap_or_default();

let is_dir = entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false);

entries.push(DirEntry {
name,
path: entry_path.display().to_string(),
is_dir,
depth,
});
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprint!("{}", stderr);
std::process::exit(output.status.code().unwrap_or(1));
}

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ls exits non-zero, this returns early and only prints stderr, discarding any stdout that ls may have produced (e.g., ls existing missing prints valid listings + an error). To preserve native behavior, print the (filtered) stdout even on failure, print stderr as well, and then exit with the same status code.

Copilot uses AI. Check for mistakes.
Comment thread src/ls.rs
Comment on lines +47 to 49
print!("{}", filtered);
tracking::track("ls", "rtk ls", &raw, &filtered);

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracking::track should include the actual command+args being proxied (and the effective default when no args are provided) so tracking remains accurate/consistent with other commands (e.g., src/cargo_cmd.rs:41-46 uses formatted command strings). Right now it always records original_cmd as "ls" and omits args, which will skew token-savings analytics.

Copilot uses AI. Check for mistakes.
@pszymkowiak pszymkowiak merged commit fe4e0f9 into rtk-ai:master Feb 1, 2026
6 of 7 checks passed
FlorianBruniaux added a commit to FlorianBruniaux/rtk that referenced this pull request Feb 1, 2026
The previous PR rtk-ai#38 contained BREAKING CHANGE in the commit message,
which triggered an unintended major version bump to 1.0.0.

This commit:
- Updates manifest to 0.7.1
- Updates Cargo.toml to 0.7.1

After merging, close PR rtk-ai#39 without merging to skip the 1.0.0 release.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
fix: convert rtk ls from reimplementation to native proxy
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
The previous PR rtk-ai#38 contained BREAKING CHANGE in the commit message,
which triggered an unintended major version bump to 1.0.0.

This commit:
- Updates manifest to 0.7.1
- Updates Cargo.toml to 0.7.1

After merging, close PR rtk-ai#39 without merging to skip the 1.0.0 release.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

3 participants