<commit_before>require 'thor'
require_relative '../ioc'
require_relative '../evaluation/agent'
require_relative '../evaluation/repository'

module Citac
  module Main
    module CLI
      class Eval < Thor
        desc 'once <connection>', 'Executes a single evaluation task'
        def once(connection)
          agent = create_agent connection
          agent.run_once
        end

        desc 'agent <connection>', 'Executes evaluation tasks continuously.'
        def agent(connection)
          agent = create_agent connection
          agent.run
        end

        no_commands do
          def create_agent(connection)
            task_repository = create_repository connection
            spec_repository = ServiceLocator.specification_repository
            env_mgr = ServiceLocator.environment_manager

            Citac::Main::Evaluation::EvaluationAgent.new task_repository, spec_repository, env_mgr
          end

          def create_repository(connection)
            case
              when connection.start_with?('local:')
                match = /^local:(?<path>.+)$/i.match connection
                raise "Wrong LOCAL connection identifier: #{connection}" unless match<commit_msg>Implemented that cache is automatically started when running evaluation.<commit_after>require 'thor'
require_relative '../ioc'
require_relative '../evaluation/agent'
require_relative '../evaluation/repository'
require_relative '../../commons/utils/exec'
require_relative '../../commons/utils/colorize'

module Citac
  module Main
    module CLI
      class Eval < Thor
        desc 'once <connection>', 'Executes a single evaluation task'
        def once(connection)
          agent = create_agent connection
          agent.run_once
        end

        desc 'agent <connection>', 'Executes evaluation tasks continuously.'
        def agent(connection)
          agent = create_agent connection
          agent.run
        end

        no_commands do
          def create_agent(connection)
            task_repository = create_repository connection
            spec_repository = ServiceLocator.specification_repository
            env_mgr = ServiceLocator.environment_manager

            ensure_cache_running

            Citac::Main::Evaluation::EvaluationAgent.new task_repository, spec_repository, env_mgr
          end

          def ensure_cache_running
            Citac::Utils::Exec.run 'citac', :args => %w(cache enable)
          rescue Exception => e
            puts "Starting cache failed: #{e}".red
          end

          def create_repository(connection)
            case
              when connection.start_with?('local:')
                match = /^local:(?<path>.+)$/i.match connection
                raise "Wrong LOCAL connection identifier: #{connection}" unless match
{'fraction_non_alphanumeric': 0.08082975679542204, 'fraction_numerical': 0.0, 'mean_word_length': 2.37394451145959, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4907817', 'n_tokens_mistral': 670, 'n_tokens_neox': 658, 'n_words': 184}