Class: SwarmCLI::V3::RebootTool
- Inherits:
-
SwarmSDK::V3::Tools::Base
- Object
- SwarmSDK::V3::Tools::Base
- SwarmCLI::V3::RebootTool
- Defined in:
- lib/swarm_cli/v3/reboot_tool.rb
Overview
Tool that triggers a process reboot with continuation message.
Writes a signal file scoped to the current PID. The CLI checks for pending signals after each agent.ask() completes and calls Kernel.exec to replace the process with a fresh Ruby invocation.
Signal files are PID-scoped (+signal_<pid>.json+) so multiple CLI sessions sharing the same agent directory don’t interfere.
Class Attribute Summary collapse
-
.session_pid ⇒ Integer?
PID of the CLI session that owns this tool instance.
Class Method Summary collapse
-
.consume_signal(directory, pid) ⇒ Hash?
Read and delete the signal file, returning the parsed data.
-
.creation_requirements ⇒ Array<Symbol>
Constructor requirements.
-
.signal_path_for(directory, pid) ⇒ String
Compute the signal file path for a given PID.
-
.signal_pending?(directory, pid) ⇒ Boolean
Check if a reboot signal is pending for the given PID.
Instance Method Summary collapse
-
#execute(continuation_message:, reason: nil) ⇒ String
Write a reboot signal file for the CLI to detect.
-
#initialize(directory:) ⇒ RebootTool
constructor
A new instance of RebootTool.
-
#name ⇒ String
Tool display name.
Constructor Details
#initialize(directory:) ⇒ RebootTool
Returns a new instance of RebootTool.
84 85 86 87 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 84 def initialize(directory:) super() @directory = File.(directory) end |
Class Attribute Details
.session_pid ⇒ Integer?
PID of the CLI session that owns this tool instance. Set by the CLI at startup.
28 29 30 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 28 def session_pid @session_pid end |
Class Method Details
.consume_signal(directory, pid) ⇒ Hash?
Read and delete the signal file, returning the parsed data.
44 45 46 47 48 49 50 51 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 44 def consume_signal(directory, pid) path = signal_path_for(directory, pid) return unless File.exist?(path) data = JSON.parse(File.read(path), symbolize_names: true) File.delete(path) data end |
.creation_requirements ⇒ Array<Symbol>
Returns Constructor requirements.
20 21 22 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 20 def creation_requirements [:directory] end |
.signal_path_for(directory, pid) ⇒ String
Compute the signal file path for a given PID.
58 59 60 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 58 def signal_path_for(directory, pid) File.join(File.(directory), ".swarm", "reboot", "signal_#{pid}.json") end |
.signal_pending?(directory, pid) ⇒ Boolean
Check if a reboot signal is pending for the given PID.
35 36 37 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 35 def signal_pending?(directory, pid) File.exist?(signal_path_for(directory, pid)) end |
Instance Method Details
#execute(continuation_message:, reason: nil) ⇒ String
Write a reboot signal file for the CLI to detect.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 99 def execute(continuation_message:, reason: nil) pid = self.class.session_pid return error("session_pid not set — Reboot tool requires CLI integration") unless pid if .nil? || .strip.empty? return validation_error("continuation_message is required") end signal = { continuation_message: , reason: reason, timestamp: Time.now.iso8601, pid: pid, } path = self.class.signal_path_for(@directory, pid) FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.pretty_generate(signal)) "Reboot signal written. The process will restart after this response completes. " \ "Your continuation message has been saved and will be sent as the first prompt after reboot." end |
#name ⇒ String
Returns Tool display name.
90 91 92 |
# File 'lib/swarm_cli/v3/reboot_tool.rb', line 90 def name "Reboot" end |