Skip to content

fix: improve command robustness and flag support#14

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
FlorianBruniaux:fix/critical-command-bugs
Jan 29, 2026
Merged

fix: improve command robustness and flag support#14
pszymkowiak merged 1 commit intortk-ai:masterfrom
FlorianBruniaux:fix/critical-command-bugs

Conversation

@FlorianBruniaux
Copy link
Collaborator

Summary

  • Lint crash handling: Graceful error messages when linters crash (OOM, SIGABRT)
  • Grep --type flag: Filter by file type (e.g., --type ts, --type py)
  • Find --type flag: Filter by file/directory type (default: f)

Motivation

Testing on Méthode Aristote revealed:

  1. ESLint crashes silently with SIGABRT on large projects
  2. Missing --type flag caused parse errors in grep/find
  3. Users expect file type filtering for focused searches

Changes

src/lint_cmd.rs

  • Detect signal-based termination (SIGABRT, SIGKILL)
  • Display user-friendly warning with stderr preview
  • Prevent silent failures on OOM scenarios

src/grep_cmd.rs + src/main.rs

  • Add --type/-t optional flag for file type filtering
  • Pass flag to ripgrep's --type for efficient filtering
  • Example: rtk grep "export" --type ts

src/find_cmd.rs + src/main.rs

  • Add --type/-t flag with default value "f" (files)
  • Support "f" (file) and "d" (directory) filtering
  • Example: rtk find "*.tsx" --type f

Testing

  • cargo check passes
  • cargo build --release succeeds
  • rtk grep --help shows new --file-type flag
  • rtk find --help shows new --file-type flag with default
  • ✅ Manual testing on Méthode Aristote project

Backwards Compatibility

No breaking changes

  • All flags are optional or have defaults
  • Existing commands work unchanged

Note

The "vitest routing bug" was user error (calling rtk test tests/unit/lib instead of rtk vitest run). No code changes needed.

🤖 Generated with Claude Code

## Fixes

### Lint crash handling
- Add graceful error handling for linter crashes (SIGABRT, OOM)
- Display warning message when process terminates abnormally
- Show first 5 lines of stderr for debugging context

### Grep command
- Add --type/-t flag for file type filtering (e.g., --type ts, --type py)
- Passes --type argument to ripgrep for efficient filtering

### Find command
- Add --type/-t flag for file/directory filtering
- Default: "f" (files only)
- Options: "f" (file), "d" (directory)

## Testing
- ✅ cargo check passes
- ✅ cargo build --release succeeds
- ✅ rtk grep --help shows --file-type flag
- ✅ rtk find --help shows --file-type flag with default

## Breaking Changes
None - all changes are backwards compatible additions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 29, 2026 16:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds file type filtering flags to the grep and find commands, and improves error handling for linter crashes.

Changes:

  • Added --file-type flag to grep and find commands for filtering by file/directory type
  • Improved lint command to detect and report signal-based process termination (e.g., SIGABRT, OOM)
  • Enhanced robustness when external tools crash or are terminated abnormally

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/main.rs Added file_type parameter to Find and Grep command structs with appropriate defaults
src/lint_cmd.rs Added signal termination detection to provide user-friendly warning messages when linters crash
src/grep_cmd.rs Updated to accept and pass file_type parameter to ripgrep's --type flag
src/find_cmd.rs Updated to accept and pass file_type parameter to fd/find's --type flag
Comments suppressed due to low confidence (1)

src/grep_cmd.rs:33

  • The file_type parameter is only applied to the ripgrep command but not to the fallback grep command. When ripgrep is unavailable and grep is used instead, the file type filtering will be silently ignored. Consider either: (1) documenting that file_type filtering requires ripgrep, (2) implementing file type filtering for the grep fallback (though standard grep doesn't have built-in type filtering), or (3) returning an error if file_type is specified but ripgrep is unavailable.
        .or_else(|_| {
            Command::new("grep")
                .args(["-rn", pattern, path])
                .output()
        })

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +12
pub fn run(pattern: &str, path: &str, max_results: usize, file_type: &str, verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("find: {} in {}", pattern, path);
}

let output = Command::new("fd")
.args([pattern, path, "--type", "f"])
.args([pattern, path, "--type", file_type])
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The new file_type parameter is not covered by any tests. Since this codebase has comprehensive test coverage (as seen in grep_cmd.rs and other files), consider adding tests to verify the file_type parameter is correctly passed to both fd and find commands.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
if let Some(ft) = file_type {
rg_cmd.arg("--type").arg(ft);
}
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The new file_type parameter is not covered by any tests. Since this codebase has comprehensive test coverage (as seen in the existing tests at the end of this file), consider adding tests to verify the file_type parameter is correctly passed to ripgrep when specified.

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +174
#[arg(short = 't', long, default_value = "f")]
file_type: String,
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The PR description claims this adds a '--type' flag, but the actual flag name will be '--file-type' (with short form '-t'). This is because clap converts the field name 'file_type' to '--file-type' with kebab-case. Consider either updating the PR description to reflect the actual flag name, or explicitly setting the flag name using '#[arg(short = 't', long = "type")]' to match the description.

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +228
#[arg(short = 't', long)]
file_type: Option<String>,
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The PR description claims this adds a '--type' flag, but the actual flag name will be '--file-type' (with short form '-t'). This is because clap converts the field name 'file_type' to '--file-type' with kebab-case. Consider either updating the PR description to reflect the actual flag name, or explicitly setting the flag name using '#[arg(short = 't', long = "type")]' to match the description.

Copilot uses AI. Check for mistakes.
@pszymkowiak pszymkowiak merged commit c2cd691 into rtk-ai:master Jan 29, 2026
6 of 7 checks passed
FlorianBruniaux added a commit to FlorianBruniaux/rtk that referenced this pull request Jan 30, 2026
Updates documentation to reflect all features added in recent PRs:

**Version Updates**
- Update installation commands to v0.3.1 (DEB/RPM packages)

**New Sections**
- Add Global Flags section (-u/--ultra-compact, -v/--verbose)
- Add JavaScript/TypeScript Stack section (10 new commands)

**New Commands Documented**
- Files: `rtk smart` (heuristic code summary)
- Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config`
- Data: `rtk gain --quota` and `--tier` flags
- Containers: `rtk kubectl services`
- JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma

**Features Coverage**
This update documents functionality from:
- PR rtk-ai#5: Git argument parsing improvements
- PR rtk-ai#6: pnpm support
- PR rtk-ai#9: Modern JavaScript/TypeScript stack support
- PR rtk-ai#10: GitHub CLI integration
- PR rtk-ai#11: Quota analysis features
- PR rtk-ai#14: Additional command improvements

All commands documented are available in v0.3.1.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
FlorianBruniaux added a commit to FlorianBruniaux/rtk that referenced this pull request Jan 30, 2026
Updates documentation to reflect all features added in recent PRs:

**Version Updates**
- Update installation commands to v0.3.1 (DEB/RPM packages)

**New Sections**
- Add Global Flags section (-u/--ultra-compact, -v/--verbose)
- Add JavaScript/TypeScript Stack section (10 new commands)

**New Commands Documented**
- Files: `rtk smart` (heuristic code summary)
- Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config`
- Data: `rtk gain --quota` and `--tier` flags
- Containers: `rtk kubectl services`
- JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma

**Features Coverage**
This update documents functionality from:
- PR rtk-ai#5: Git argument parsing improvements
- PR rtk-ai#6: pnpm support
- PR rtk-ai#9: Modern JavaScript/TypeScript stack support
- PR rtk-ai#10: GitHub CLI integration
- PR rtk-ai#11: Quota analysis features
- PR rtk-ai#14: Additional command improvements

All commands documented are available in v0.3.1.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
…d-bugs

fix: improve command robustness and flag support
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
Updates documentation to reflect all features added in recent PRs:

**Version Updates**
- Update installation commands to v0.3.1 (DEB/RPM packages)

**New Sections**
- Add Global Flags section (-u/--ultra-compact, -v/--verbose)
- Add JavaScript/TypeScript Stack section (10 new commands)

**New Commands Documented**
- Files: `rtk smart` (heuristic code summary)
- Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config`
- Data: `rtk gain --quota` and `--tier` flags
- Containers: `rtk kubectl services`
- JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma

**Features Coverage**
This update documents functionality from:
- PR rtk-ai#5: Git argument parsing improvements
- PR rtk-ai#6: pnpm support
- PR rtk-ai#9: Modern JavaScript/TypeScript stack support
- PR rtk-ai#10: GitHub CLI integration
- PR rtk-ai#11: Quota analysis features
- PR rtk-ai#14: Additional command improvements

All commands documented are available in v0.3.1.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
navidemad added a commit to navidemad/rtk that referenced this pull request Mar 1, 2026
- Fix misleading correctable count comment in rubocop_cmd.rs to explain
  the 0-value ambiguity (absent field vs genuinely zero) (issue rtk-ai#8)
- Update compact_minitest_failure doc to describe full behavior including
  message line context (issue rtk-ai#14)
- Add JSON-parse-failure fallback mention to rspec_cmd.rs and
  rubocop_cmd.rs module-level docs (issue rtk-ai#15)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants