Skip to content

feat: accept legacy -N line counts in head and tail - #171

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/head-tail-legacy-count
Oct 23, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/head-tail-legacy-count

Conversation

@ferdingler

@ferdingler ferdingler commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

head and tail only understood -n 3, so the short legacy form like head -3 file or tail -20 failed with an unknown option. Agents write that form all the time, so a lot of ordinary commands just errored out.

Now a leading -N means -n N for both commands, the same way GNU coreutils reads it. Like GNU, only the first argument counts, so anything after -- stays a filename and a count in a later position is still rejected. The byte-count options work as before.

Evidence of how we fixed it in Box

Box has its own fix for this (here); this version is written fresh for upstream, since Box's also treats a filename after -- as a count.

Related Issues

None.

Documentation PR

None.

Type of Change

New feature

Testing

I compared the cases against GNU head and tail locally and they match, apart from one: GNU tail refuses a legacy count combined with -n, and here the later option wins, the same as head. On main the new legacy-count tests failed. I also tried the simpler version that rewrites every -N argument, and the tests for a dash-named file after -- caught it. The full Rust suite passes and clippy shows no new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

head -3 file and tail -20 now mean -n 3 and -n 20, as in GNU coreutils.
Only the first argument is read as a legacy count, so a dash-prefixed
operand after -- stays a filename.
@ferdingler
ferdingler requested a review from a team as a code owner October 21, 2026 04:46
@ferdingler
ferdingler requested review from mehtarac and removed request for a team October 21, 2026 04:46
@ferdingler
ferdingler requested a review from a team as a code owner October 23, 2026 00:20
@ferdingler
ferdingler merged commit 07df899 into strands-agents:main Oct 23, 2026
30 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.

2 participants