Class: Aidp::CLI::JobsCommand

Inherits:
Object
  • Object
show all
Includes:
MessageDisplay
Defined in:
lib/aidp/cli/jobs_command.rb

Constant Summary

Constants included from MessageDisplay

MessageDisplay::COLOR_MAP

Instance Method Summary collapse

Methods included from MessageDisplay

#display_message, #in_test_environment?, included, #message_display_prompt, #suppress_display_message?

Constructor Details

#initialize(input: nil, output: nil, prompt: TTY::Prompt.new) ⇒ JobsCommand

Returns a new instance of JobsCommand.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/aidp/cli/jobs_command.rb', line 17

def initialize(input: nil, output: nil, prompt: TTY::Prompt.new)
  @io = TerminalIO.new(input: input, output: output)
  @prompt = prompt
  @pastel = Pastel.new
  @running = true
  @view_mode = :list
  @selected_job_id = nil
  @jobs_displayed = false # Track if we've displayed jobs in interactive mode
  @file_manager = Aidp::Storage::FileManager.new(File.join(Dir.pwd, ".aidp"))
  @background_runner = Aidp::Jobs::BackgroundRunner.new(Dir.pwd)
  @screen_width = 80 # Default screen width
end

Instance Method Details

#list_jobsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/aidp/cli/jobs_command.rb', line 65

def list_jobs
  jobs = @background_runner.list_jobs

  if jobs.empty?
    display_message("Background Jobs", type: :info)
    display_message("-" * @screen_width, type: :muted)
    display_message("")
    display_message("No background jobs found", type: :info)
    display_message("")
    display_message("Start a background job with:", type: :info)
    display_message("  aidp execute --background", type: :info)
    display_message("  aidp analyze --background", type: :info)
    return
  end

  render_background_jobs(jobs)
end

#run(subcommand = nil, args = []) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/aidp/cli/jobs_command.rb', line 34

def run(subcommand = nil, args = [])
  case subcommand
  when "list", nil
    list_jobs
  when "status"
    job_id = args.shift
    if job_id
      show_job_status(job_id, follow: args.include?("--follow"))
    else
      display_message("Usage: aidp jobs status <job_id> [--follow]", type: :error)
    end
  when "stop"
    job_id = args.shift
    if job_id
      stop_job(job_id)
    else
      display_message("Usage: aidp jobs stop <job_id>", type: :error)
    end
  when "logs"
    job_id = args.shift
    if job_id
      show_job_logs(job_id, tail: args.include?("--tail"), follow: args.include?("--follow"))
    else
      display_message("Usage: aidp jobs logs <job_id> [--tail] [--follow]", type: :error)
    end
  else
    display_message("Unknown jobs subcommand: #{subcommand}", type: :error)
    display_message("Available: list, status, stop, logs", type: :info)
  end
end

#show_job_logs(job_id, tail: false, follow: false) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/aidp/cli/jobs_command.rb', line 107

def show_job_logs(job_id, tail: false, follow: false)
  if follow
    display_message("Following logs for job #{job_id} (Ctrl+C to exit)...", type: :info)
    @background_runner.follow_job_logs(job_id)
  else
    logs = @background_runner.job_logs(job_id, tail: tail, lines: 50)
    unless logs
      display_message("No logs found for job: #{job_id}", type: :error)
      return
    end

    display_message("Logs for job #{job_id}:", type: :info)
    display_message("-" * @screen_width, type: :muted)
    puts logs
  end
end

#show_job_status(job_id, follow: false) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aidp/cli/jobs_command.rb', line 83

def show_job_status(job_id, follow: false)
  if follow
    follow_job_status(job_id)
  else
    status = @background_runner.job_status(job_id)
    unless status
      display_message("Job not found: #{job_id}", type: :error)
      return
    end

    render_job_status(status)
  end
end

#stop_job(job_id) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/aidp/cli/jobs_command.rb', line 97

def stop_job(job_id)
  result = @background_runner.stop_job(job_id)

  if result[:success]
    display_message("✓ #{result[:message]}", type: :success)
  else
    display_message("✗ #{result[:message]}", type: :error)
  end
end