From c4db4691114be20c68ce732c9b1adc722f3be0a5 Mon Sep 17 00:00:00 2001 From: Artem Yegorov Date: Wed, 10 Jun 2026 17:35:51 +0300 Subject: [PATCH 1/2] feat: add `--search` flag to filter models (#128) --- lib/classifier/cli.rb | 22 ++++++++++-- test/cli/registry_commands_test.rb | 58 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/lib/classifier/cli.rb b/lib/classifier/cli.rb index 6c673942..8698c46a 100644 --- a/lib/classifier/cli.rb +++ b/lib/classifier/cli.rb @@ -95,6 +95,10 @@ def parse_options @options[:type] = type end + opts.on('--search TEXT', 'Find models by name or description. Use quotes for multiword search') do |text| + @options[:search] = text + end + opts.on('-r', '--remote MODEL', 'Use remote model: name or @user/repo:name') do |model| @options[:remote] = model end @@ -376,12 +380,20 @@ def list_remote_models return if @exit_code != 0 - if index['models'].empty? + models = index['models'] + + unless @options[:search].nil? + models = models.filter do |name, info| + [name, info['description']].any?(/#{Regexp.escape(@options[:search])}/i) + end + end + + if models.empty? @output << 'No models found in registry' return end - index['models'].each do |name, info| + models.each do |name, info| type = info['type'] || 'unknown' size = info['size'] || 'unknown' desc = info['description'] || '' @@ -413,6 +425,12 @@ def list_local_models models = default_models + custom_models #: Array[{name: String, registry: String?, path: String}] + unless @options[:search].nil? + models = models.filter do |model| + model[:name] =~ /#{Regexp.escape(@options[:search])}/i + end + end + if models.empty? @output << 'No local models found' return diff --git a/test/cli/registry_commands_test.rb b/test/cli/registry_commands_test.rb index 613d8c3d..e0fb7acf 100644 --- a/test/cli/registry_commands_test.rb +++ b/test/cli/registry_commands_test.rb @@ -151,6 +151,64 @@ def test_models_local_shows_no_models_when_cache_dir_missing assert_match(/no local models found/i, result[:output]) end + def test_models_remote_search_by_name + stub_request(:get, 'https://raw.githubusercontent.com/cardmagic/classifier-models/main/models.json') + .to_return(status: 200, body: @models_json) + + result = run_cli('models', '--search', 'spam-filter') + + assert_equal 0, result[:exit_code] + assert_match(/spam-filter/, result[:output]) + refute_match(/sentiment/, result[:output]) + end + + def test_models_remote_search_by_decription + stub_request(:get, 'https://raw.githubusercontent.com/cardmagic/classifier-models/main/models.json') + .to_return(status: 200, body: @models_json) + + result = run_cli('models', '--search', 'Spam Detection') + + assert_equal 0, result[:exit_code] + assert_match(/spam-filter/, result[:output]) + refute_match(/sentiment/, result[:output]) + end + + def test_models_remote_search_no_found + stub_request(:get, 'https://raw.githubusercontent.com/cardmagic/classifier-models/main/models.json') + .to_return(status: 200, body: @models_json) + + result = run_cli('models', '--search', '[a-z]+') + + assert_equal 0, result[:exit_code] + assert_match(/No models found in registry/, result[:output]) + end + + def test_models_local_search_by_name + # Create some cached models + models_dir = File.join(@cache_dir, 'models') + FileUtils.mkdir_p(models_dir) + File.write(File.join(models_dir, 'spam-filter.json'), @model_json) + File.write(File.join(models_dir, 'sentiment.json'), @model_json) + + result = run_cli('models', '--local', '--search', 'spam-filter') + + assert_equal 0, result[:exit_code] + assert_match(/spam-filter/, result[:output]) + refute_match(/sentiment/, result[:output]) + end + + def test_models_local_search_no_found + # Create some cached models + models_dir = File.join(@cache_dir, 'models') + FileUtils.mkdir_p(models_dir) + File.write(File.join(models_dir, 'spam-filter.json'), @model_json) + + result = run_cli('models', '--local', '--search', '[a-z]+') + + assert_equal 0, result[:exit_code] + assert_match(/No local models found/, result[:output]) + end + # # Pull Command # From ea3358acd848e826c9868d505435717c98d2d571 Mon Sep 17 00:00:00 2001 From: Artem Yegorov Date: Wed, 10 Jun 2026 18:05:22 +0300 Subject: [PATCH 2/2] fix: greptile comments (#128) --- lib/classifier/cli.rb | 9 ++++++--- test/cli/registry_commands_test.rb | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/classifier/cli.rb b/lib/classifier/cli.rb index 8698c46a..001e4163 100644 --- a/lib/classifier/cli.rb +++ b/lib/classifier/cli.rb @@ -95,7 +95,10 @@ def parse_options @options[:type] = type end - opts.on('--search TEXT', 'Find models by name or description. Use quotes for multiword search') do |text| + opts.on( + '--search TEXT', + 'Search remote models by name/description, and local models by name only. Use quotes for multiword search' + ) do |text| @options[:search] = text end @@ -382,7 +385,7 @@ def list_remote_models models = index['models'] - unless @options[:search].nil? + if @options[:search] models = models.filter do |name, info| [name, info['description']].any?(/#{Regexp.escape(@options[:search])}/i) end @@ -425,7 +428,7 @@ def list_local_models models = default_models + custom_models #: Array[{name: String, registry: String?, path: String}] - unless @options[:search].nil? + if @options[:search] models = models.filter do |model| model[:name] =~ /#{Regexp.escape(@options[:search])}/i end diff --git a/test/cli/registry_commands_test.rb b/test/cli/registry_commands_test.rb index e0fb7acf..a658217e 100644 --- a/test/cli/registry_commands_test.rb +++ b/test/cli/registry_commands_test.rb @@ -162,7 +162,7 @@ def test_models_remote_search_by_name refute_match(/sentiment/, result[:output]) end - def test_models_remote_search_by_decription + def test_models_remote_search_by_description stub_request(:get, 'https://raw.githubusercontent.com/cardmagic/classifier-models/main/models.json') .to_return(status: 200, body: @models_json)