Class: RubyLLM::Toolbox::Tools::ProcessStart

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

Overview

EXEC. Starts a long-running background process (a dev server, a file watcher, a log tail) and returns its id immediately instead of blocking. Read its output later with process_output, see everything running with process_list, and stop it with process_kill.

Same safety model as bash: one allowlisted executable, argv only (no shell), the minimal env_passthrough environment, run in fs_root, in its own process group with an address-space cap. Concurrency is bounded by config.max_processes.

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(command:, args: nil, name: nil, unsafe: false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_llm/toolbox/tools/process_start.rb', line 41

def execute(command:, args: nil, name: nil, unsafe: false)
  exe = resolve_command(command, unsafe)
  argv = [exe, *sanitize_args(args)]

  id = ProcessRegistry.start(
    argv: argv,
    env: clean_env,
    chdir: config.fs_root,
    name: (name.to_s.empty? ? exe : name.to_s),
    rlimits: memory_rlimits,
    max: config.max_processes
  )
  proc = ProcessRegistry.get(id)
  "Started #{id} (pid #{proc.pid}): #{argv.inspect}\nUse process_output id:#{id.inspect} to read its output."
rescue Safety::CommandGuard::Blocked => e
  error(e.message, code: :command_denied)
rescue ProcessRegistry::LimitError => e
  error(e.message, code: :too_many_processes)
end