Skip to content

cat -n a b is rewritten to rtk read -n a b, which restarts the numbering at each file and names no file #4889

Open

Description

@KuSh

cat -n a b is rewritten to rtk read -n a b, which numbers each file from 1 with nothing marking where one file ends and the next begins. GNU cat -n a b keeps counting across files.

Steps to reproduce

seq 1 9 > a.txt; seq 1 10 > b.txt
rtk rewrite 'cat -n a.txt b.txt'   # rtk read -n a.txt b.txt
cat -n a.txt b.txt | tail -3      # 17 8 / 18 9 / 19 10
rtk read -n a.txt b.txt | tail -3 # " 8 8" / " 9 9" / "10 10"

Expected

Either the numbering of cat -n, which keeps counting across files (line 10 = b.txt line 1), or numbers per file with a header for each file, so the agent can tell which file a line comes from.

Actual

The numbering restarts at 1 for each file and no file name is printed (exit 0). On develop 41e6912 with the │ separator, the same thing happens. Once #4647's tab separator lands, the output looks exactly like cat -n output, so a line number the agent got from an earlier native cat -n a b points at a different line.

Found during review of #4647.

The guard that decides this rewrite is being reworked in #4593 and #4341 (cat_options_map_to_read); requiring exactly one file there would also close this.

Activity

  1. rtk-wshm-sync-bot commented on Oct 31, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 90%

    Summary

    cat -n a b → rtk read -n a b restarts numbering per file and prints no filename, breaking line-number correspondence with native cat -n; tighten the cat→read rewrite guard to only fire for single-file invocations.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/cat_options_map_to_read.rs

    Suggested Actions

    1. Fix via fix(rewrite): read every cat flag, not just the first #4593/refactor(cmdline): one borrowed token type with separator and newline kinds #4341's cat_options_map_to_read rework: require exactly one file before rewriting
    2. Cross-check against rtk read -n (target of the cat -n rewrite) drops carriage returns and adds a final newline #4816 (rtk read -n already mishandles CR/final newline) and fix(read): separate line numbers with a tab #4647 (separator change)
    3. Add regression test: cat -n a.txt b.txt vs rtk read -n a.txt b.txt on multi-file input

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions