Class: WritersRoom::Producer
- Inherits:
-
Object
- Object
- WritersRoom::Producer
- Defined in:
- lib/writers_room/producer.rb
Overview
Producer manages the overall production: creates characters, scenes, and coordinates directors to run the full production.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Class Method Summary collapse
-
.create_project(project_path, name:, concept: "", medium: "dialog", **config_options) ⇒ Object
Create a new project with concept.
Instance Method Summary collapse
-
#chat_about_production(scene_files) ⇒ Object
Chat about production planning.
-
#create_character(name, traits = {}) ⇒ Object
Create a new character from a template (.md with front matter).
-
#create_scene(name, description, characters = []) ⇒ Object
Create a new scene (.md with front matter).
-
#generate_report ⇒ Object
Generate a production report across all transcripts.
-
#initialize(project_path = Dir.pwd) ⇒ Producer
constructor
A new instance of Producer.
-
#list_characters ⇒ Object
List all characters in the project.
-
#list_scenes ⇒ Object
List all scenes in the project.
-
#produce(scene_files = nil, options = {}) ⇒ Object
Run a full production (all scenes or specific scenes).
-
#validate_project ⇒ Object
Validate that the project has the required structure.
Constructor Details
#initialize(project_path = Dir.pwd) ⇒ Producer
Returns a new instance of Producer.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/writers_room/producer.rb', line 12 def initialize(project_path = Dir.pwd) @project_path = File.(project_path) unless File.exist?(File.join(@project_path, "config.yml")) || File.exist?(File.join(@project_path, "project.md")) raise Error, "No project found. Run 'wr init <project_name>' first." end = ProjectMetadata.new(@project_path) ensure_project_structure end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/writers_room/producer.rb', line 10 def end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
10 11 12 |
# File 'lib/writers_room/producer.rb', line 10 def project_path @project_path end |
Class Method Details
.create_project(project_path, name:, concept: "", medium: "dialog", **config_options) ⇒ Object
Create a new project with concept
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/writers_room/producer.rb', line 25 def self.create_project(project_path, name:, concept: "", medium: "dialog", **) FileUtils.mkdir_p(project_path) # Write config.yml if it doesn't already exist config_path = File.join(project_path, "config.yml") unless File.exist?(config_path) config_data = { "provider" => [:provider] || "ollama", "model_name" => [:model_name] || "gpt-oss:20b" } File.write(config_path, YAML.dump(config_data)) end # Create metadata with concept and medium (saves as .md) ProjectMetadata.create(project_path, name: name, concept: concept, medium: medium) # Create required directories based on medium producer = new(project_path) producer.send(:ensure_project_structure) producer end |
Instance Method Details
#chat_about_production(scene_files) ⇒ Object
Chat about production planning
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/writers_room/producer.rb', line 141 def chat_about_production(scene_files) require_relative "chat_session" scenes_list = scene_files.map { |f| File.basename(f) }.join(", ") context = { project_name: .name, project_concept: .concept, task: "Planning production", subject: "Production Planning", additional: "Available scenes: #{scenes_list}\nTotal scenes: #{scene_files.count}" } session = ChatSession.new(context: context) session.start chat_log_path = File.join(@project_path, "production_chat_#{Time.now.to_i}.md") session.save(chat_log_path) { chat_log: chat_log_path, summary: session.summary, messages: session. } end |
#create_character(name, traits = {}) ⇒ Object
Create a new character from a template (.md with front matter)
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 |
# File 'lib/writers_room/producer.rb', line 60 def create_character(name, traits = {}) characters_dir = File.join(@project_path, "characters") FileUtils.mkdir_p(characters_dir) character_file = File.join(characters_dir, "#{sanitize_filename(name)}.md") if File.exist?(character_file) raise Error, "Character '#{name}' already exists" end = { "name" => name, "traits" => { "personality" => traits[:personality] || "neutral", "speaking_style" => traits[:speaking_style] || "conversational", "background" => traits[:background] || "" }, "goals" => traits[:goals] || [], "relationships" => traits[:relationships] || {} } body = "" content = FrontMatter.dump(, body) File.write(character_file, content) character_file end |
#create_scene(name, description, characters = []) ⇒ Object
Create a new scene (.md with front matter)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/writers_room/producer.rb', line 87 def create_scene(name, description, characters = []) scenes_dir = File.join(@project_path, "scenes") FileUtils.mkdir_p(scenes_dir) scene_file = File.join(scenes_dir, "#{sanitize_filename(name)}.md") if File.exist?(scene_file) raise Error, "Scene '#{name}' already exists" end = { "scene_name" => name, "description" => description, "setting" => "", "characters" => characters, "objectives" => [] } body = "" content = FrontMatter.dump(, body) File.write(scene_file, content) scene_file end |
#generate_report ⇒ Object
Generate a production report across all transcripts
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/writers_room/producer.rb', line 216 def generate_report transcripts_dir = File.join(@project_path, "transcripts") return {} unless Dir.exist?(transcripts_dir) transcripts = Dir.glob(File.join(transcripts_dir, "*.txt")) total_lines = 0 total_characters = {} transcripts.each do |transcript| content = File.read(transcript) in_dialog = false content.each_line do |line| # Dialog starts after the separator line if line.start_with?("---") in_dialog = true next end next unless in_dialog next if line.strip.empty? # Match "character_name:" or "character_name [emotion]:" match = line.match(/^(\w+)(\s+\[.*?\])?:\s/) next unless match character = match[1] total_characters[character] ||= 0 total_characters[character] += 1 total_lines += 1 end end { total_scenes: transcripts.count, total_lines: total_lines, lines_by_character: total_characters, transcripts: transcripts.map { |t| File.basename(t) } } end |
#list_characters ⇒ Object
List all characters in the project
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/writers_room/producer.rb', line 111 def list_characters characters_dir = File.join(@project_path, "characters") return [] unless Dir.exist?(characters_dir) Dir.glob(File.join(characters_dir, "*.md")).map do |file| data = load_character_file(file) { name: data["name"] || data[:name], file: file, personality: data.dig("traits", "personality") || data.dig(:traits, :personality) } end end |
#list_scenes ⇒ Object
List all scenes in the project
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/writers_room/producer.rb', line 126 def list_scenes scenes_dir = File.join(@project_path, "scenes") return [] unless Dir.exist?(scenes_dir) Dir.glob(File.join(scenes_dir, "*.md")).map do |file| data = load_scene_file(file) { name: data["scene_name"] || data[:scene_name], file: file, characters: data["characters"] || data[:characters] || [] } end end |
#produce(scene_files = nil, options = {}) ⇒ Object
Run a full production (all scenes or specific scenes)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/writers_room/producer.rb', line 168 def produce(scene_files = nil, = {}) scene_files ||= find_scene_files scene_files = [scene_files] if scene_files.is_a?(String) results = [] scene_files.each do |scene_file| unless File.exist?(scene_file) puts "Warning: Scene file not found: #{scene_file}" next end puts "=" * 60 puts "PRODUCING SCENE: #{File.basename(scene_file)}" puts "=" * 60 director = Director.new( scene_file: scene_file, character_dir: File.join(@project_path, "characters"), max_lines: [:max_lines] ) begin director.action! transcript_file = director.save_transcript([:output]) results << { scene: scene_file, transcript: transcript_file, statistics: director.statistics, status: :completed } rescue => e puts "Error producing scene: #{e.message}" results << { scene: scene_file, error: e., status: :failed } ensure director.cut! rescue nil end end results end |
#validate_project ⇒ Object
Validate that the project has the required structure
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/writers_room/producer.rb', line 48 def validate_project required_dirs = scaffolded_dirs_for_medium missing = required_dirs.reject { |dir| Dir.exist?(File.join(@project_path, dir)) } if missing.any? raise Error, "Missing required directories: #{missing.join(', ')}" end true end |