Skip to content

feat: add --search flag to filter models (#128)#157

Open
Yegorov wants to merge 2 commits into
cardmagic:masterfrom
Yegorov:128
Open

feat: add --search flag to filter models (#128)#157
Yegorov wants to merge 2 commits into
cardmagic:masterfrom
Yegorov:128

Conversation

@Yegorov

@Yegorov Yegorov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Closes #128

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a --search TEXT flag to the models command that filters the displayed model list by a case-insensitive substring match against name and description (remote) or name only (local).

  • Remote search (list_remote_models) checks both model name and description using Regexp.escape-guarded regex, which is safe against regex injection.
  • Local search (list_local_models) filters only by file name, despite the help text advertising "name or description" — a user querying --local --search "spam detection" will get no hits even when a matching description exists in the cached JSON.
  • Both filter blocks use unless @options[:search].nil? instead of the idiomatic Ruby if @options[:search].

Confidence Score: 3/5

The --search feature works correctly for remote models, but local model search silently ignores descriptions despite the help text promising both — users can get misleading no-results responses.

The local search filter only matches on file name while list_remote_models checks name and description. The CLI help text says 'Find models by name or description' for both modes, so any user running --local --search with a description term gets a wrong answer with no indication why. That behavioral gap should be resolved before merging.

lib/classifier/cli.rb — specifically the list_local_models search filter and the --search option help text.

Important Files Changed

Filename Overview
lib/classifier/cli.rb Adds --search flag with filtering in both list_remote_models and list_local_models; local search only matches on name while the help text promises name-or-description, and the unless ... nil? pattern appears twice instead of the simpler if.
test/cli/registry_commands_test.rb Adds five tests covering remote/local search by name, by description, and empty-result cases; one test method name has a typo (decription) and there is no local-search-by-description test (matching the behavioral gap in the implementation).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[models command] --> B{--local flag?}
    B -- yes --> C[list_local_models]
    B -- no --> D[list_remote_models]
    C --> C1[Glob local JSON files]
    C1 --> C2{--search set?}
    C2 -- yes --> C3[Filter by name only]
    C2 -- no --> C4[All models]
    C3 --> C5{empty?}
    C4 --> C5
    C5 -- yes --> C6[No local models found]
    C5 -- no --> C7[Display local models]
    D --> D1[Fetch registry index]
    D1 --> D2{--search set?}
    D2 -- yes --> D3[Filter by name OR description]
    D2 -- no --> D4[All models]
    D3 --> D5{empty?}
    D4 --> D5
    D5 -- yes --> D6[No models found in registry]
    D5 -- no --> D7[Display remote models]
    style C3 fill:#f9c,stroke:#c66
    style D3 fill:#9cf,stroke:#69c
Loading
Prompt To Fix All With AI
Fix the following 4 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 4
lib/classifier/cli.rb:385-389
`unless ... nil?` is the verbose form of `if`. Ruby's falsy semantics cover `nil`, so the nil check is redundant and this pattern reads awkwardly. Applies to both occurrences (lines 385 and 428).

```suggestion
      if @options[:search]
        models = models.filter do |name, info|
          [name, info['description']].any?(/#{Regexp.escape(@options[:search])}/i)
        end
      end
```

In this review, suggest simpl... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

### Issue 2 of 4
lib/classifier/cli.rb:428-432
Same `unless ... nil?` anti-pattern in the local model filter. Prefer `if @options[:search]`.

```suggestion
      if @options[:search]
        models = models.filter do |model|
          model[:name] =~ /#{Regexp.escape(@options[:search])}/i
        end
      end
```

In this review, suggest simpl... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

### Issue 3 of 4
lib/classifier/cli.rb:428-432
**Local search ignores descriptions, but the flag says otherwise.** The `--search` option is advertised as "Find models by name or description," but `list_local_models` only matches on `model[:name]`. A user who runs `--local --search "spam detection"` and expects a description hit will get zero results, while the same query against the remote registry would succeed. Either restrict the help text to "by name" for local mode, or load each model's JSON inside the filter block to also check `info['description']`.

### Issue 4 of 4
test/cli/registry_commands_test.rb:165
Typo in test name: `decription``description`.

```suggestion
  def test_models_remote_search_by_description
```

Reviews (1): Last reviewed commit: "feat: add `--search` flag to filter mode..." | Re-trigger Greptile

Comment thread lib/classifier/cli.rb Outdated
Comment thread lib/classifier/cli.rb Outdated
Comment thread lib/classifier/cli.rb Outdated
Comment thread test/cli/registry_commands_test.rb Outdated
@Yegorov

Yegorov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@cardmagic can you take a look, please?

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.

CLI: Add --search flag to filter models

1 participant