feat: add --search flag to filter models (#128)#157
Conversation
Greptile SummaryAdds a
Confidence Score: 3/5The --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
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
Prompt To Fix All With AIFix 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 |
|
@cardmagic can you take a look, please? |
|
Will look in about a week |
| if @options[:search] | ||
| models = models.filter do |model| | ||
| model[:name] =~ /#{Regexp.escape(@options[:search])}/i | ||
| end | ||
| end |
There was a problem hiding this comment.
Doing a local search could match descriptions at near-zero extra cost.
Remote search matches name + description, but local matches name only. That asymmetry is fine and it's documented in the help text, so this isn't a bug. Just noting that the usual reason to skip description matching here. Having to load + parse each model's JSON doesn't actually apply: the display loop below already calls load_model_info(model[:path]) for every model (line 443) to read its type. The JSON is parsed regardless.
So searching descriptions locally wouldn't add the I/O it appears to. One option is to load info once per model up front, then filter on both name and info['description'], reusing the same parsed hash for display.
There was a problem hiding this comment.
@cardmagic Am I correct in understanding that search by description for local models may be added in the future? That is, for new models, their description will be added to the JSON file.
Fixed, check, please.
Closes #128