Skip to content

feat(find): add -size, -mtime, -mmin and -newer - #221

Merged
ferdingler merged 1 commit into
strands-agents:mainfrom
ferdingler:feat/find-size-time
Nov 12, 2026
Merged

ferdingler merged 1 commit into
strands-agents:mainfrom
ferdingler:feat/find-size-time

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

find only knew name, path, type and empty tests. Filtering by size or age failed, so agents couldn't use those common ways to narrow a file search.

This adds -size, -mtime, -mmin and -newer with GNU-style comparisons, including rounded-up size units, fractional ages and strictly newer reference times. These predicates use the metadata the kernel provides: copy binds reset file mtimes and VFS directories have size zero, so direct binds are needed for host timestamp queries and -type f restricts size queries to files. Traversal and existing actions stay unchanged, and -delete remains separate while direct-bind symlink behavior is addressed.

I compared the results against GNU find on the same directly bound files, including sizes and ages around the day and minute boundaries, and all 45 CLI probes matched. The tests set real mtimes so they don't depend on timing, and the full local Rust suite, doc tests, formatting, clippy and docs checks pass.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce 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.

@ferdingler ferdingler closed this Nov 6, 2026
@ferdingler ferdingler reopened this Nov 6, 2026
@ferdingler
ferdingler marked this pull request as ready for review November 12, 2026 20:13
@ferdingler
ferdingler requested a review from a team as a code owner November 12, 2026 20:13
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. I found nothing blocking: -size, -mtime, -mmin and -newer matched GNU find 4.9 in every realistic case I ran on a direct bind, and the error messages and exit codes match too.

Two non-blocking questions. Neither is caused by this PR, but both change what agents get back from the new predicates on the default setup:

  • Copy binds (the default mode) reset mtimes. copy_from_host creates each file through vfs.create_file (src/vfs.rs:873), which stamps SystemTime::now() (src/vfs.rs:74). So on a copy bind, a 3-day-old file doesn't match find . -mtime +1, every file matches -mtime -1, and -newer compares the times the bind was made. On a direct bind the same files give GNU's answer. Should we preserve host mtimes on copy, or document this?
  • VFS directories report size 0 (src/vfs.rs:605, InodeData::Dir(_) => (..., 0)). That means find . -size -1k and find . -size 0 also list . and every directory, which GNU doesn't do on ext4. -type f avoids it. Fix it, or leave it?

The red CI rollup isn't a real failure. Run 43298099046 was cancelled by a newer run on the same SHA, and that run (43298190383) passed all 29 jobs, including CI Gate.

✅ What I verified
  • Head: 8a42977, which merges cleanly onto main.
  • Tests: cargo test --test shell_integration find passed 54/54, including the 8 new tests. The full shell_integration suite (1632 tests) passed 3 times in a row. find_mtime_boundaries_match_gnu passed 80 runs under parallel load.
  • Lint: cargo clippy --all-targets adds no new warnings, and cargo fmt --check is clean.
  • Comparison against GNU find 4.9, direct bind:
    • My own run: 29 cases, 0 differences. Sizes 0, 1, 511, 512, 513, 1023, 1024, 1025 and 1048577 bytes against 15 -size arguments. mtimes 30 s, 59.5 s, 60.5 s, 119 s, 86399.5 s, 86400.5 s and 172801 s old, plus one 100 s in the future, against -mmin/-mtime with 0, 1, -1, +0, +1, 0.5, -0.5 and -0.
    • An independent adversarial run: 45 commands, with only the overflow divergence in the appendix.
    • Bad-argument messages match GNU byte for byte. -newer with !, -o and parentheses, with a relative reference, and with a missing reference (exit 1) all behave like GNU.
  • Copy vs direct, same host dir with touch -d '3 days ago' old: find . -mtime +1 gives nothing on a copy bind and ./old on a direct bind (GNU also gives ./old). find . -size 0 gives . ./empty on a copy bind and ./empty on a direct bind (GNU: ./empty).
  • Tests are well built. The time tests set real mtimes on a direct bind, the same fixture proves -newer is strict, and the error tests assert the exact stderr and exit code.

Repro scripts and output are uploaded as gnu-diff.sh, gnu-diff-output.txt and adversarial-repro-output.txt.

Reading order

Read parse_age first (src/builtins/find.rs:141), since that's where GNU's off-by-one day shift lives. Then the Age arm in eval_expr (:387), then resolve_times (:160), then the find_mtime_boundaries_match_gnu test.

Appendix: non-blocking (3)
  • ⚪ Overflowing numbers parse as inf. Arguments of about 309 or more digits, like -mtime -999…9, become inf (find.rs:146-147, Ok(n) if valid => n). -mtime -inf then matches everything instead of failing with GNU's "invalid argument" error. No real caller writes this. If you want the fix anyway, it's Ok(n) if valid && n.is_finite() => n.
  • ⚪ -mtime 1e1 is rejected, while GNU accepts exponent notation. Contrived.
  • Already known, not re-raised: on direct binds, lstat follows symlinks (src/vfs_kernel.rs:531 → tokio::fs::metadata at :1114), so -newer <symlink> uses the target's mtime. You already called this out in the PR body as the blocker for -delete.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks for checking the default copy-bind behavior too. I confirmed both metadata paths in the VFS code. I'm leaving them unchanged here because preserving copy timestamps or changing directory sizes would affect other commands as well as these new predicates.

I added both limits to the description: use a direct bind when the query needs host mtimes, and -type f when a size query should exclude directories. Preserving host mtimes on copy and deciding how virtual directories report size stay as separate VFS follow-ups. The extreme-number and exponent parsing differences can also stay in a separate compatibility fix.

The current revision's full CI run passed, including the required CI Gate; the red rollup is from the superseded run you identified.

@ferdingler
ferdingler merged commit 2adb869 into strands-agents:main Nov 12, 2026
32 of 61 checks passed
@ferdingler
ferdingler deleted the feat/find-size-time branch November 12, 2026 23:01
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