Skip to content

fix(ls): suppress summary line when stdout is piped - #503

Merged
FlorianBruniaux merged 3 commits into
rtk-ai:developfrom
ousamabenyounes:fix/ls-pipe-summary
Mar 28, 2026
Merged

FlorianBruniaux merged 3 commits into
rtk-ai:developfrom
ousamabenyounes:fix/ls-pipe-summary

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Summary

  • rtk ls | wc -l returned N+2 instead of N because the 📊 summary line and blank line were always on stdout
  • Now uses std::io::stdout().is_terminal() to suppress summary when piped
  • Follows standard Unix convention — ls, grep, find all suppress metadata when piped

Fixes #482

Before

rtk ls src/ | wc -l   # 63 (wrong, +2)
ls src/ | wc -l        # 61 (correct)

After

rtk ls src/ | wc -l   # 61 (correct, matches ls)
ls src/ | wc -l        # 61 (correct)

Changes

  • compact_ls() now returns (entries, summary) tuple instead of single String
  • run() only prints summary when stdout().is_terminal() is true
  • Token tracking (rtk gain) only counts what is actually sent to stdout

Tests added

  • test_entries_no_summary — entries never contain the 📊 line
  • test_pipe_line_count — simulates | wc -l, verifies exact count matches files+dirs

Test plan

  • cargo test ls::tests — 35 tests pass (including 2 new)
  • cargo test — 766 passed, 0 failed
  • Manual: rtk ls src/ | wc -l = ls src/ | wc -l (both 61)
  • Manual: rtk ls src/ in terminal still shows summary

🤖 Generated with Claude Code

@pszymkowiak
pszymkowiak changed the base branch from master to develop March 11, 2026 19:58
@pszymkowiak

Copy link
Copy Markdown
Collaborator

LGTM — clean fix, well tested.

Build passes, 35 ls tests pass, manual verification confirms:

  • rtk ls src/ | wc -l matches ls src/ | wc -l (61 = 61)
  • Summary 📊 visible in TTY, suppressed when piped

Minor nit (non-blocking): entries.clone() in the else branch could just be entries since it's not used after — avoids one allocation. Up to you.

@aeppling for merge.

@pszymkowiak
pszymkowiak requested a review from aeppling March 12, 2026 20:21
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Applied the entries.clone() → entries nit in c4ede93 — good catch, no need for the allocation since entries isn't used after.

Also rebased on latest develop and confirmed all 35 ls tests still pass.

Side note: we noticed a pre-existing compilation error on develop — cargo_cmd.rs:838 references a truncate function that doesn't exist in scope. This is unrelated to this PR but blocks cargo test globally. Should we open a separate issue for it?

@CLAassistant

CLAassistant commented Mar 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aeppling

Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

ousamabenyounes and others added 3 commits March 26, 2026 19:15
rtk ls | wc -l returned N+2 instead of N because the summary line
(📊 X files, Y dirs) and blank line were always written to stdout.

Now uses std::io::stdout().is_terminal() to suppress the summary
when piped, following standard Unix convention (ls, grep, find all
do this).

Fixes #482

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Ousama Ben Younes <[email protected]>
Avoids one allocation since entries is not used after the if/else.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Ousama Ben Younes <[email protected]>
Fixes Documentation Validation CI check (main.rs=64, ARCHITECTURE.md was 60).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Ousama Ben Younes <[email protected]>
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Rebased on upstream/develop (includes PR #826 reorganization). Resolved conflicts in src/cmds/system/ls.rs (kept tuple return + pipe-suppression logic) and ARCHITECTURE.md (merged HEAD directory structure with my module count). All 10 ls tests pass.

@FlorianBruniaux
FlorianBruniaux merged commit b79623c into rtk-ai:develop Mar 28, 2026
8 checks passed
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.

fix: rtk ls summary line inflates pipe count

5 participants