Class: WritersRoom::Commands::Produce

Inherits:
Thor
  • Object
show all
Defined in:
lib/writers_room/cli/produce.rb

Instance Method Summary collapse

Instance Method Details

#produce(*scene_files) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/writers_room/cli/produce.rb', line 23

def produce(*scene_files)
  require_relative "../producer"

  producer = WritersRoom::Producer.new

  # Handle graceful shutdown
  trap("INT") do
    say "\n[PRODUCER: Production interrupted]", :yellow
    exit 0
  end

  # Validate project structure
  begin
    producer.validate_project
  rescue WritersRoom::Error => e
    say "Error: #{e.message}", :red
    exit 1
  end

  # Use all scenes if none specified
  if scene_files.empty?
    scene_files = Dir.glob(File.join(Dir.pwd, "scenes", "*.md"))
    if scene_files.empty?
      say "No scene files found in scenes/ directory", :yellow
      exit 1
    end
  else
    # Convert relative paths to absolute
    scene_files = scene_files.map { |f| File.expand_path(f) }
  end

  # If chat mode, discuss production planning before running
  if options[:chat]
    say "Starting interactive chat about production planning...", :cyan
    say ""
    result = producer.chat_about_production(scene_files)

    say "\n" + "=" * 60, :green
    say "CHAT SESSION COMPLETE", :green
    say "=" * 60, :green
    say ""
    say "Summary:", :cyan
    say result[:summary], :white
    say ""
    say "Chat saved to: #{result[:chat_log]}", :yellow
    say ""
    say "Would you like to proceed with production? (y/n)", :cyan
    response = STDIN.gets&.chomp&.downcase

    unless %w[y yes].include?(response)
      say "Production cancelled.", :yellow
      exit 0
    end
  end

  say "=" * 60, :cyan
  say "STARTING PRODUCTION", :cyan
  say "=" * 60, :cyan
  say "Scenes to produce: #{scene_files.count}", :white
  scene_files.each { |f| say "  - #{File.basename(f)}", :white }
  say ""

  # Run production
  results = producer.produce(scene_files, options.transform_keys(&:to_sym))

  # Show results
  say "\n" + "=" * 60, :cyan
  say "PRODUCTION COMPLETE", :cyan
  say "=" * 60, :cyan

  successful = results.select { |r| r[:status] == :completed }
  failed = results.select { |r| r[:status] == :failed }

  say "Completed: #{successful.count}", :green
  say "Failed: #{failed.count}", :red if failed.any?

  successful.each do |result|
    say "\n#{File.basename(result[:scene])}:", :cyan
    say "  Transcript: #{result[:transcript]}", :white
    say "  Lines: #{result[:statistics][:total_lines]}", :white
  end

  if failed.any?
    say "\nFailed scenes:", :red
    failed.each do |result|
      say "  #{File.basename(result[:scene])}: #{result[:error]}", :red
    end
  end
rescue WritersRoom::Error => e
  say "Error: #{e.message}", :red
  exit 1
rescue StandardError => e
  say "Error running production: #{e.message}", :red
  say e.backtrace.join("\n"), :red if ENV["DEBUG"]
  exit 1
end