Skip to content

fix(find): accept native find flags (-name, -type, etc.) - #211

Merged
pszymkowiak merged 5 commits into
rtk-ai:masterfrom
sahilmgandhi:fix/find-positional-args
Mar 5, 2026
Merged

pszymkowiak merged 5 commits into
rtk-ai:masterfrom
sahilmgandhi:fix/find-positional-args

Conversation

@sahilmgandhi

@sahilmgandhi sahilmgandhi commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rtk find . -name "*.rs" -type f fails with unexpected argument '-n' found because Clap decomposes -name into short flags (-n, -a, -m, -e) and -n is not defined
  • Changed Find to use trailing_var_arg = true, allow_hyphen_values = true (consistent with Grep, Ls, Tree, and most other RTK commands)
  • Added parse_find_args() that detects and handles both native find syntax (-name, -type, -maxdepth, -iname) and existing RTK syntax (rtk find *.rs src -m 50 -t f)
  • Rejects unsupported compound predicates (-not, -exec, -delete, etc.) with a clear error instead of silently giving wrong results

Changes

File Change
src/main.rs Replaced named Find args with trailing_var_arg + dispatch to run_from_args()
src/find_cmd.rs Added parse_find_args() with native/RTK syntax detection, FindArgs with Default, next_arg helper. Fixed -maxdepth to wire to WalkBuilder::max_depth (traversal depth, not display limit). -iname now performs case-insensitive glob matching. Unsupported flags (-not, -exec, etc.) bail with clear error. 15 new tests.

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets clean
  • cargo test find_cmd — 27/27 tests pass (15 new)
  • cargo test --all — 409/409 tests pass
  • Manual test: rtk find . -name "*.rs" -type f — works, returns compact output
📁 58F 4D:

src/ cargo_cmd.rs cc_economics.rs ccusage.rs config.rs container.rs curl_cmd.rs deps.rs diff_cmd.rs display_helpers.rs env_cmd.rs filter.rs find_cmd.rs format_cmd.rs gain.rs gh_cmd.rs git.rs go_cmd.rs golangci_cmd.rs grep_cmd.rs hook_audit_cmd.rs init.rs json_cmd.rs lint_cmd.rs local_llm.rs log_cmd.rs ls.rs main.rs next_cmd.rs npm_cmd.rs pip_cmd.rs playwright_cmd.rs pnpm_cmd.rs prettier_cmd.rs prisma_cmd.rs pytest_cmd.rs read.rs ruff_cmd.rs runner.rs summary.rs tee.rs tracking.rs tree.rs tsc_cmd.rs utils.rs vitest_cmd.rs wc_cmd.rs wget_cmd.rs
src/discover/ mod.rs provider.rs registry.rs

@pszymkowiak pszymkowiak 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.

Nice work! Clean approach, consistent with how we handle git.rs and grep_cmd.rs (trailing_var_arg + manual parsing). Auto-detection of native vs RTK syntax is smart.

15 new tests, security is fine (-exec properly rejected), -iname and -maxdepth are good additions.

One thing to fix before merge:

In parse_native_find_args(), unknown flags are silently swallowed by the _ => {} catch-all. This means rtk find . -mindepth 2 -name "*.rs" succeeds but ignores -mindepth — the user thinks it works but gets wrong results.

Please add a warning on stderr for unknown flags:

_ => {
    eprintln!("rtk find: unknown flag '{}', ignored", args[i]);
}

This way users know their flag was dropped instead of getting silently wrong results.

Everything else looks good — small fix and we can merge 👍

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for this PR! Clean approach, consistent with how we handle git.rs and grep_cmd.rs (trailing_var_arg + manual parsing). Auto-detection of native vs RTK syntax is smart.

Tests are solid (15 new), security is fine (-exec properly rejected), and -iname / -maxdepth are nice additions.

One thing to fix before merge: in parse_native_find_args(), unknown flags are silently swallowed by the _ => {} catch-all. I tested with -mindepth and it succeeds without warning — the
user thinks it works but gets wrong results.

_ => {
eprintln!("rtk find: unknown flag '{}', ignored", args[i]);
}

Small fix and we can merge — thanks again!

@sahilmgandhi

Copy link
Copy Markdown
Contributor Author

Thank you for the review @pszymkowiak, I took a pass at it, and updated the PR accordingly.

@aros3rg3d

Copy link
Copy Markdown

Thanks! It close #170 as well :)

@nikaiw nikaiw mentioned this pull request Feb 20, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Review: PR #211

The find implementation is solid — auto-detection of native vs RTK syntax, clear rejection of unsupported flags (-not, -exec, etc.), and good test coverage (27 tests).

Local testing confirmed everything works:

  • rtk find . -name "*.rs" -type f — correct, 58 files grouped by directory
  • rtk find "*.toml" — RTK syntax works
  • rtk find . -iname "cargo.toml" — case-insensitive works
  • rtk find . -name "*.rs" -maxdepth 1 — depth limiting works
  • rtk find . -not -name "*test*" — correctly rejected with clear error message
  • rtk find . -exec rm {} \; — correctly rejected

One issue: the branch needs a rebase on current master (ab5dbb1). The diff shows deletions in gh_cmd.rs, git.rs, grep_cmd.rs, playwright_cmd.rs and main.rs that are just missing upstream additions (markdown filter, rtk wc, grep -n flag, etc.). The find code itself is clean — only find_cmd.rs and its routing in main.rs should change.

Fix: git rebase master and resolve conflicts keeping upstream changes. After that, this is ready to merge.

@sahilmgandhi
sahilmgandhi force-pushed the fix/find-positional-args branch from 7a4b64c to 93419c1 Compare February 22, 2026 22:31
@sahilmgandhi

Copy link
Copy Markdown
Contributor Author

Thanks, I rebased to master and fixed the diffs to keep only the changed files.

heAdz0r added a commit to heAdz0r/rtk that referenced this pull request Feb 28, 2026
…tk-ai#217, rtk-ai#196, rtk-ai#248, rtk-ai#211, rtk-ai#200, rtk-ai#192, rtk-ai#268)

Wave 1 (critical bugs):
- fix(registry): fi/done moved to IGNORED_EXACT — find no longer shadowed (rtk-ai#246)
- fix(playwright): f64 duration, specs[] structure, --reporter=json after subcmd (rtk-ai#193)
- fix(gh): should_passthrough_gh_view for --json/--jq/--template/--web in view_pr/issue/run (rtk-ai#217+196)

Wave 2 (reliability):
- fix(git): is_blob_show_arg — blob show passthrough without trailing-newline trim (rtk-ai#248)
- fix(find): parse_find_args with native -name/-type/-maxdepth/-iname support (rtk-ai#211)
- fix(main): graceful Clap fallback + parse_failures SQLite table + rtk gain --failures (rtk-ai#200)

Wave 3 (UX):
- feat(git): global options -C/-c/--git-dir/--work-tree/--no-pager/--no-optional-locks/--bare/--literal-pathspecs (rtk-ai#192)
- feat(proxy): streaming output via spawn()+threads instead of buffered output() (rtk-ai#268)

Tests: 1091 → 1117 (+26), 0 regressions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Re-tested locally after rebase — all clean.

  • 446/446 tests pass (27 find-specific)
  • Native syntax works: find . -name "*.rs" -type f, -maxdepth, -iname
  • Unsupported flags properly rejected: -not, -exec → clear error message
  • Unknown flags warned: -mindepthrtk find: unknown flag '-mindepth', ignored
  • RTK syntax still works: find "*.toml" → backwards compatible
  • Diff is clean — only find_cmd.rs, main.rs + minor cargo fmt in 2 files

All previous review items addressed. LGTM, ready to merge.

@sahilmgandhi

Copy link
Copy Markdown
Contributor Author

Thanks @pszymkowiak , you marked the PR as DONE_REVIEW, is there a workflow that picks this up to make the PR mergeable? I am unable to merge it right now:

image

@pszymkowiak
pszymkowiak merged commit 7ac5bc4 into rtk-ai:master Mar 5, 2026
2 of 3 checks passed
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
* fix(find): accept native find flags (-name, -type, etc.)

* fix: apply cargo fmt after merge

* Merge master into fix/find-positional-args

Update git -C test for new global options support, apply fmt.
@reneleonhardt

Copy link
Copy Markdown

What would be needed to make compound predicates possible?

$ rtk find ../parallel-project -type f \( -name "*.swift" -o -name "*.plist" -o -name "*.entitlements" -o -name "Package.swift" \) | head -50
rtk: rtk find does not support compound predicates or actions (e.g. -not, -exec). Use `find` directly.

thehoff added a commit to thehoff/contextcrawler that referenced this pull request Jul 14, 2026
…ai#211)

`check()` called `wait_timeout` BEFORE reading the child's piped stdout.
The kernel pipe buffer is ~64 KiB, so a tirith verdict larger than that
blocked tirith on write, `wait_timeout` never saw it exit, and the 8s
timeout turned a real BLOCK into a fail-OPEN `Unavailable`.

Fix: a reader thread drains stdout concurrently with the wait (up to
CAP+1 to detect overflow), so the child can always finish writing. The
read/parse logic is extracted to a pure, tested `interpret_tirith_stdout`;
an OVERFLOW (> TIRITH_STDOUT_MAX) now fails CLOSED as a synthetic block
(caller downgrades to Ask) rather than degrading to auto-allow. A genuine
timeout stays `Unavailable` (the default-off contract; a hung tirith must
not prompt-storm).

Refs: rtk-ai#211

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3SAimSBwPUp4MkRXaYXSU
thehoff added a commit to thehoff/contextcrawler that referenced this pull request Jul 14, 2026
Large security release completing the codex-5.6-max sweep + 5-voice
council audit (rtk-ai#210-rtk-ai#233): rtk-ai#219/rtk-ai#220 (hook-tamper validation rebuild +
trust store), rtk-ai#225 (non-Claude handler gating), rtk-ai#212-rtk-ai#218/rtk-ai#230
(permission gate + lexer), rtk-ai#211 (Tirith deadlock), rtk-ai#222 (config
injection), rtk-ai#226/rtk-ai#232/rtk-ai#233 (filter engine). The two big clusters were
authored by the Codex worker in isolated worktrees, driver-verified and
non-author-council-reviewed. See CHANGELOG.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3SAimSBwPUp4MkRXaYXSU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants