diff --git a/src/amber_cli/commands/database.cr b/src/amber_cli/commands/database.cr index 4813718..712a35c 100644 --- a/src/amber_cli/commands/database.cr +++ b/src/amber_cli/commands/database.cr @@ -104,7 +104,7 @@ module AmberCLI::Commands when "create" create_database when "seed" - Amber::CLI::Helpers.run("crystal db/seeds.cr", wait: true, shell: true) + Amber::CLI::Helpers.run("crystal db/seeds.cr", wait: true) info "Seeded database" when "migrate" migrate diff --git a/src/amber_cli/helpers/helpers.cr b/src/amber_cli/helpers/helpers.cr index 1816bbe..16d2f35 100644 --- a/src/amber_cli/helpers/helpers.cr +++ b/src/amber_cli/helpers/helpers.cr @@ -77,11 +77,13 @@ module Amber::CLI::Helpers File.write(app_file_path, application.gsub(injection_marker, replacement)) if deps.size > 0 end - def self.run(command, wait = true, shell = true) + def self.run(command : String, wait = true) + parsed_args = Process.parse_arguments(command) + cmd = parsed_args.shift? || "" if wait - Process.run(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) + Process.run(cmd, args: parsed_args, shell: false, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) else - Process.new(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) + Process.new(cmd, args: parsed_args, shell: false, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) end rescue ex : IO::Error # typically means we could not find the executable diff --git a/src/amber_cli/helpers/process_runner.cr b/src/amber_cli/helpers/process_runner.cr index 34c5ea0..6f826f8 100644 --- a/src/amber_cli/helpers/process_runner.cr +++ b/src/amber_cli/helpers/process_runner.cr @@ -148,7 +148,7 @@ module Sentry end private def start_process(run_command_run) - process = Amber::CLI::Helpers.run(run_command_run, wait: false, shell: false) + process = Amber::CLI::Helpers.run(run_command_run, wait: false) if process.is_a? Process @processes["run"] ||= Array(Process).new @processes["run"] << process @@ -178,7 +178,7 @@ module Sentry end log task, "Starting..." - process = Amber::CLI::Helpers.run(run_command, wait: false, shell: true) + process = Amber::CLI::Helpers.run(run_command, wait: false) if process.is_a? Process @processes[task] ||= Array(Process).new @processes[task] << process diff --git a/src/amber_cli/vendor/inflector/ai_transformer.cr b/src/amber_cli/vendor/inflector/ai_transformer.cr index a01d92f..f4e36bf 100644 --- a/src/amber_cli/vendor/inflector/ai_transformer.cr +++ b/src/amber_cli/vendor/inflector/ai_transformer.cr @@ -23,6 +23,9 @@ module AmberCLI::Vendor::Inflector::AITransformer end end + # Cache limit to prevent memory leaks in persistent instances + MAX_CACHE_SIZE = 1000 + # Cache for AI transformation results @@cache = {} of String => String @@config = Config.new @@ -41,11 +44,17 @@ module AmberCLI::Vendor::Inflector::AITransformer # Check cache first cache_key = "#{word}:#{transformation}" if cached_result = @@cache[cache_key]? + # Move to end (most recently used) + @@cache.delete(cache_key) + @@cache[cache_key] = cached_result return cached_result end # Try AI transformation if result = call_ai_service(word, transformation) + if @@cache.size >= MAX_CACHE_SIZE + @@cache.delete(@@cache.first_key) + end @@cache[cache_key] = result return result end