Skip to content

head -n N file has no rewrite rule while tail -n N file does #3667

Closed

Description

@dwin-gharibi

Type: Enhancement (coverage gap) · Severity: Low · Area: src/discover/registry.rs

Summary

rewrite_line_range handles four tail spellings but only two head spellings. The
space-separated forms — head -n N file and head --lines N file — fall through unrewritten,
even though tail -n N file and tail --lines N file are both handled.

Command Rewrite
head -20 f.txt rtk read f.txt --max-lines 20
head -n 20 f.txt none
head --lines=20 f.txt rtk read f.txt --max-lines 20
head --lines 20 f.txt none
tail -20 f.txt rtk read f.txt --tail-lines 20
tail -n 20 f.txt rtk read f.txt --tail-lines 20
tail --lines=20 f.txt rtk read f.txt --tail-lines 20
tail --lines 20 f.txt rtk read f.txt --tail-lines 20

Impact

No correctness problem — the command runs natively and returns the right answer. It is lost
savings on one of the most common commands an agent types, and head -n 20 is the more idiomatic
spelling of the two that are handled.

Root cause

static HEAD_N_SPACE and HEAD_LINES_SPACE simply do not exist; the tail arm has its
equivalents.

Environment

  • rtk 0.42.4 (develop @ 29f9bb7)

Activity

  1. added
    enhancement
    good first issue
    on Aug 23, 2026
  2. pszymkowiak commented on Aug 23, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟢 Priority low
    🎯 Confidence 90%

    Summary

    Add rewrite rules for head -n N file and head --lines N file (space-separated forms), matching the coverage already present for tail.

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

    📁 Relevant files
    • src/discover/registry.rs

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

  3. MincongZhou commented on Sep 23, 2026

    @MincongZhou

    Already fixed on develop — HEAD_N_SPACE / HEAD_LINES_SPACE were added in #3941 (ed8480f, merged 2026-09-13). Both spellings from the table now rewrite.

    Verified against rtk 0.48.0, develop @ b748a5f:

    $ cargo test test_rewrite_head
    test discover::registry::tests::test_rewrite_head_n_space_flag ... ok
    test discover::registry::tests::test_rewrite_head_lines_space_flag ... ok
    ...
    test result: ok. 15 passed; 0 failed
    

    src/discover/registry.rs:96 today, registered in the loop at :1348:

    // `-n N` and `--lines N` are the spellings `tail` already accepted below; `head`
    // silently fell through to no rewrite at all without them.
    static HEAD_N_SPACE: LazyLock<Regex> =
        LazyLock::new(|| Regex::new(r"^head\s+-n\s+(\d+)\s+(\S+)$").unwrap());
    static HEAD_LINES_SPACE: LazyLock<Regex> =
        LazyLock::new(|| Regex::new(r"^head\s+--lines\s+(\d+)\s+(\S+)$").unwrap());

    The test comment for test_rewrite_head_expanding_operand_stays_native even records it: "Covers the newly added -n N / --lines N routes, which had no matcher at all before and so were native by accident."

    All four spellings in the table rewrite now. Suggest closing as completed.

  4. KuSh commented on Sep 26, 2026

    @KuSh
    Collaborator

    Fixed by #3941, shipped in v0.50.0: head -n N file and head --lines N file now rewrite to rtk read file --head-lines N, the same as the other head and tail spellings. If you still see one of these fall through on the latest version, please comment or reopen.

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:clienhancementgood first issuepriority:low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions