Class: RailsDoctor::Agent::Handoff
- Inherits:
-
Object
- Object
- RailsDoctor::Agent::Handoff
- Defined in:
- lib/rails_doctor/agent/handoff.rb
Instance Attribute Summary collapse
-
#agent_name ⇒ Object
readonly
Returns the value of attribute agent_name.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
-
#initialize(agent_name:, project:, config:, runner:, options:) ⇒ Handoff
constructor
A new instance of Handoff.
- #run(scan_result) ⇒ Object
Constructor Details
#initialize(agent_name:, project:, config:, runner:, options:) ⇒ Handoff
Returns a new instance of Handoff.
13 14 15 16 17 18 19 |
# File 'lib/rails_doctor/agent/handoff.rb', line 13 def initialize(agent_name:, project:, config:, runner:, options:) @agent_name = agent_name @project = project @config = config @runner = runner @options = end |
Instance Attribute Details
#agent_name ⇒ Object (readonly)
Returns the value of attribute agent_name.
11 12 13 |
# File 'lib/rails_doctor/agent/handoff.rb', line 11 def agent_name @agent_name end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/rails_doctor/agent/handoff.rb', line 11 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/rails_doctor/agent/handoff.rb', line 11 def @options end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
11 12 13 |
# File 'lib/rails_doctor/agent/handoff.rb', line 11 def project @project end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
11 12 13 |
# File 'lib/rails_doctor/agent/handoff.rb', line 11 def runner @runner end |
Instance Method Details
#run(scan_result) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_doctor/agent/handoff.rb', line 21 def run(scan_result) agent_config = config.agent(agent_name) raise Error, "Unknown agent #{agent_name.inspect}" unless agent_config findings = filtered_findings(scan_result.findings) brief = build_brief(scan_result, findings) brief_path = write_brief(brief) output = +"Wrote agent brief: #{brief_path}\n" output << "Findings included: #{findings.size}\n" if [:apply] ensure_clean_worktree!(agent_config) command = "#{agent_config.fetch("command")} #{Shellwords.escape(brief_path)}" command_result = runner.run(command, timeout_seconds: 900) audit_path = write_audit(scan_result, findings, brief_path, command, command_result) output << "Invoked #{agent_name}: exit #{command_result.exit_status}\n" output << "Audit trail: #{audit_path}\n" output << command_result.stdout unless command_result.stdout.to_s.empty? output << command_result.stderr unless command_result.stderr.to_s.empty? else output << "No agent was invoked. Re-run with --apply to execute #{agent_name}.\n" end output end |