Repository navigation
fix(ls): preserve hierarchy for -R + passthrough incompatible flags (#714) - #1251
pszymkowiak wants to merge 3 commits into
Conversation
…#714) - Recursive ls output now shows directory headers + indented children so the LLM can tell which files live in which directory. Previously every entry was collapsed into a flat list that lost all path information. - Incompatible flags (-1, -d, -F, -C, -m, -x, -i, -p) change ls output format enough that our `ls -la` parser breaks. Pass those through to raw ls so users still get the expected behavior. Supersedes #799 — ported to the new `runner::run_filtered` architecture. Signed-off-by: Patrick szymkowiak <[email protected]>
📊 Automated PR Analysis
SummaryFixes recursive ls output to preserve directory hierarchy by introducing compact_ls_recursive() that emits subsection headers with indented children, and adds a passthrough path for flags incompatible with the ls -la parser. This ensures LLM agents can distinguish which files belong to which directory instead of seeing a flat list. Review Checklist
Linked issues: #714 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Merge develop into the branch. ls.rs now follows develop's plan/render pipeline: -R is detected from the parsed arguments, and each directory section is compacted under its own header so a listing still says which directory each entry belongs to. The never-worse guard against native ls still applies.
Only the separator colon is removed from a section header, so a directory named 'dir:' keeps its name. A long-format line ending in ':' (a file operand such as 'file:') is an entry, not a header. Adds tests for the flag detection and the indented long listing.
KuSh
left a comment
There was a problem hiding this comment.
Round 2 of 3 — CHANGES REQUESTED
Claim: rtk ls -R keeps the directory each entry belongs to (#714), section by section, instead of flattening the tree.
Scope: accept (frozen from this round on; the flag passthrough in the description is no longer in the diff). Maintainer PRs: checked against #5099 (KuSh): long_name is gone there, so whichever of the two lands second changes the recursive line to a Flag constant (two lines; merged with that change, both test sets pass, 5644/0). Checked against #4103 (KuSh): ls.rs hunks are disjoint.
Ran: real GNU ls (coreutils, LC_ALL=C child, one fr_FR run), develop 8bb6096 vs this head merged onto it, 35 rows: the #714 tree, -R/-lR/-laR/--recursive/--rec/-lRd/-R1/-g -R/--format=long/--, file + dir operands, no operand (.:), empty dir, unreadable subdir (exit 1), missing operand (exit 2), names with spaces and colons (dir:, a:b, file:), noise dirs, 60/55/2- and 75-entry sections, rtk's own src/; invariants: under the hook (every row via rtk rewrite, recall hint followed), over-cap + accounting, split streams, non-default targets, every decision; savings -lR src 59%, -laR src/cmds 66%, -lR src/cmds/system 57% vs 20% floor (CONTRIBUTING.md); plain -R prints native byte for byte (0%, correct: the indented form is larger, so never_worse keeps native).
Pins: 13 decisions, 16 mutations, 7 survived: 3 are below (item 2), 1 is item 1's total conjunct, 1 is the -R gate (Optional 3), 2 change nothing on any input ls can print (the empty-headerless-section continue, and dropping ends_with(':'))
Matrix: never run before; executed this round. Pin check: never run before; executed this round.
CI @c1eef2a3: all green (22/22); merged onto develop 8bb6096: fmt, clippy, 5571 tests pass.
Blocks merge (2)
src/cmds/system/ls.rs:453,:434— section markers matched by text a real name can spell (2 sites, both must change).(empty): a file named(empty)in a names-only section is dropped by the line filter, with no notice.rtk ls -R h6bwithh6b/dholding(empty)+ 80 long names: 49 shown +... (31 more)= 80 of 81. develop lists it. The marker is compact_ls's own output; it can only be told apart from a file of that name by what compact_ls parsed (a file named(empty)is never noise, and it is never the only line left by truncation).total: atotal Nline never ends in:, so!line.starts_with("total ")only ever rejects real headers.rtk ls -lR other 'total stuff'drops bothtotal stuff:andtotal stuff/in:with no notice, anda,in/,qprint flush-left right afterother:'s entries.
Rows a fix must satisfy:ls -R h6b→dshows 50 +(31 more)= 81,(empty)among them;ls -lR other 'total stuff'→total stuff:andtotal stuff/in:headers witha/in/andqindented under them; a section that is really empty or noise-only still prints its header alone.
src/cmds/system/ls.rs:444,:445,:338— unpinned behaviour (per-section accounting, and the-Rwiring inrun). Thelsunit tests andtests/ls_never_worse_test.rsall pass under each of:truncated.extend(cut)→truncated.extend(cut.into_iter().take(0)): the... (N more)notice and its recall vanish. Test must: sections of 60, 55 and 2 entries → 15 truncated, shown + truncated = 117.filtered.extend(hid)→filtered.extend(hid.into_iter().take(0)): anode_modulesdropped in a subsection is no longer counted. Test must:node_modulesin a non-first section →filtered == ["node_modules/"].- in
run,render(…, recursive, …)→render(…, false, …): develop's flat listing is back.ls_never_worse_test's-Rcase only checks size. Test must run the binary:rtk ls -lRon a temp tree withsub/notes.md→ the line after./sub:isnotes.mdindented.
Each mutation must turn its test red.
Optional — will not hold merge
- A cut section's notice and recall lose the directory (
ls.rs:442).rtk ls -lR big2(aaa 60, bbb 55, ccc 2):aaaandbbbshow 50 each with no marker,... (15 more)prints afterccc(which was not cut), andrtk recallreturnsa51…a60 b51…b55with no directory. develop's flat listing loses the directory too, so this is not a regression, but it is the hierarchy this PR is about, for any directory over 50 entries. A per-section... (N more)anddir/namelines in the stored part would close it. I'll file it if you'd rather keep it out of this PR. - Noise dirs are counted as filtered but their sections print in full.
rtk ls -lR odd:node_modules/andtarget/are in... (2 filtered)in theodd:section, thenodd/node_modules:,odd/node_modules/pkg:,odd/target/debug:are all listed. Same offer. - The
-Rgate:ls a bprints the samedir:sections and stays on the flat path (#2857, which #2865 targets). No test decides between the two; callingcompact_recursivefor every listing closes #2857 as well. Your call; either way a test should pin it. - Blank lines between sections (thread from round 1): 25 B of 7064 on
ls -lR src(0.35%), and they matchls. Fine as is; resolving the thread.
Checked and correct — no need to re-verify
- #714's tree:
-lRhierarchy correct, 273 B vs 657 B native;-R= native. - Headers with colons (
odd/dir::,odd/a:b:), names with spaces, a file operand namedfile:(stays an entry), file operands before the first header (unindented),.:with no operand. --recursive,--rec,-laR,-g -R,--format=long,--all reach the recursive path;-lRdand-R1behave like develop.- Failure paths unchanged: unreadable subdir (exit 1) and missing operand (exit 2) print what
lsprinted, stderr forwarded. - Accounting on a single cut section: 3 + 2 + 50 shown + 25 = 80.
fr_FRshell: same output (the child runs underLC_ALL=C).- A name with an embedded blank line cannot fake a section (the child prints
?); with--show-control-charsnativelsis equally ambiguous. - Round-1 stderr thread: that code is gone; the runner forwards non-empty stderr on every exit (
src/core/runner.rs:354). Resolving it.
Next
Item 1 (both sites) and item 2's three tests; please also update the title and description to the current claim (the flag passthrough and the April before/after are no longer in the diff). Round 3 then lands it by fixup or approval.
Rounds: 2/3. Threads: 2 open (item 1, item 2), 2 resolved this round (round-1 threads).
| } | ||
| out.push_str(path); | ||
| out.push_str(":\n"); | ||
| for line in entries.lines().filter(|line| *line != "(empty)") { |
There was a problem hiding this comment.
Blocks merge, item 1: this filter drops a real file named (empty) (rtk ls -R h6b: 80 of 81 entries, no notice; develop lists it). The same class is at line 434: !line.starts_with("total ") can only reject a real header, since a total N line never ends in : (rtk ls -lR other 'total stuff' loses both of its headers). Rows a fix must satisfy are in the review body.
|
|
||
| let (entries, count, cut, hid) = compact_ls(&body.join("\n"), show_all, show_long); | ||
| parsed_count += count; | ||
| truncated.extend(cut); |
There was a problem hiding this comment.
Blocks merge, item 2: no test fails when this line becomes truncated.extend(cut.into_iter().take(0)). The same holds for filtered.extend(hid) at line 445 and for render(…, false, …) in place of recursive at line 338. The tests that would kill each mutation are listed in the review body.
Supersedes #799 — that PR was based on the pre-refacto
src/ls.rsand could not be rebased cleanly after the move tosrc/cmds/system/ls.rswith the newrunner::run_filteredarchitecture. Ported the fix to the current codebase.Closes #714
Changes
Recursive hierarchy (
rtk ls -Rflattens recursive output and loses hierarchy context #714)compact_ls_recursive()parsesls -laRsections and emits:/path/to/dir:Incompatible flags passthrough
-1,-d,-F,-C,-m,-x,-i,-pchange ls output format enough that ourls -laparser breaks.Before/After
Tests
cargo test— 1386 passed, 0 failed, 0 regressionscompact_ls_recursive(hierarchy + empty subdir edge case)rtk ls -R,rtk ls -1,rtk lsall work as expectedcargo fmt --all+cargo clippy --all-targetsclean