Class: RubyLLM::Toolbox::Tools::ProcessKill

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_llm/toolbox/tools/process_kill.rb

Overview

SAFE. Stops a background process: SIGTERM to its process group, escalating to SIGKILL if it doesn’t exit, then returns any final output. Always available (even if exec tools are later disabled) so a runaway can always be stopped. Removes the process from the registry.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(id:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_llm/toolbox/tools/process_kill.rb', line 21

def execute(id:)
  proc = ProcessRegistry.get(id)
  return error("no such process: #{id}", code: :not_found) unless proc

  was_running = proc.running?
  proc.kill
  final = proc.read_new
  ProcessRegistry.delete(id)

  body = +"#{id} #{was_running ? 'terminated' : 'was already exited'}"
  body << " (exit #{proc.exit_code})" if proc.exit_code
  unless final[:out].empty? && final[:err].empty?
    body << "\n--- final stdout ---\n#{final[:out]}" unless final[:out].empty?
    body << "\n--- final stderr ---\n#{final[:err]}" unless final[:err].empty?
  end
  truncate(body)
end