Class: WritersRoom::Writer
- Inherits:
-
Object
- Object
- WritersRoom::Writer
- Defined in:
- lib/writers_room/writer.rb
Overview
Writer helps develop the story: expands concepts, develops characters, creates story arcs, and breaks down scenes.
Uses RobotLab template switching: each method updates the robot's template + context before running, rather than inlining prompts.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
-
#robot ⇒ Object
readonly
Returns the value of attribute robot.
Instance Method Summary collapse
-
#breakdown_scenes(arc_name, num_scenes: 5, chat: false) ⇒ Object
Break down an arc into scene suggestions.
-
#create_arc(arc_name, description, chat: false) ⇒ Object
Create a story arc.
-
#develop_character(name, basic_info = {}, chat: false) ⇒ Object
Develop a character profile from basic information.
-
#develop_concept(chat: false) ⇒ Object
Develop the project concept into a fuller description using LLM.
-
#initialize(project_path = Dir.pwd) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(project_path = Dir.pwd) ⇒ Writer
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/writers_room/writer.rb', line 15 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) setup_robot end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/writers_room/writer.rb', line 13 def end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
13 14 15 |
# File 'lib/writers_room/writer.rb', line 13 def project_path @project_path end |
#robot ⇒ Object (readonly)
Returns the value of attribute robot.
13 14 15 |
# File 'lib/writers_room/writer.rb', line 13 def robot @robot end |
Instance Method Details
#breakdown_scenes(arc_name, num_scenes: 5, chat: false) ⇒ Object
Break down an arc into scene suggestions
164 165 166 167 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 |
# File 'lib/writers_room/writer.rb', line 164 def breakdown_scenes(arc_name, num_scenes: 5, chat: false) arc = .story_arcs.find { |a| a["name"] == arc_name } unless arc raise Error, "Arc '#{arc_name}' not found. Create it first with 'wr write create-arc'." end if chat chat_result = chat_about_scene_breakdown(arc_name, arc, num_scenes) return chat_result if chat_result end @robot.update( template: :breakdown_scenes, context: { project_concept: .concept, arc_name: arc_name, arc_description: arc["description"], arc_outline: arc["outline"], num_scenes: num_scenes } ) result = @robot.run("Break this arc down into #{num_scenes} scenes.") scene_breakdown = result.reply breakdown_path = File.join(@project_path, "arcs", "#{sanitize_filename(arc_name)}_breakdown.md") File.write(breakdown_path, " # Scene Breakdown: \#{arc_name}\n\n \#{scene_breakdown}\n\n ---\n *Generated: \#{Time.now}*\n *Scenes requested: \#{num_scenes}*\n MARKDOWN\n\n {\n arc: arc_name,\n breakdown: scene_breakdown,\n saved_to: breakdown_path\n }\nend\n") |
#create_arc(arc_name, description, chat: false) ⇒ Object
Create a story arc
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/writers_room/writer.rb', line 113 def create_arc(arc_name, description, chat: false) if chat chat_result = chat_about_arc(arc_name, description) return chat_result if chat_result end @robot.update( template: :create_arc, context: { project_concept: .concept, arc_name: arc_name, arc_description: description } ) result = @robot.run("Create a detailed arc outline for \"#{arc_name}\".") arc_outline = result.reply arc_data = { "name" => arc_name, "description" => description, "outline" => arc_outline, "created_at" => Time.now.to_s } .add_story_arc(arc_data) arc_path = File.join(@project_path, "arcs", "#{sanitize_filename(arc_name)}.md") FileUtils.mkdir_p(File.dirname(arc_path)) File.write(arc_path, " # Story Arc: \#{arc_name}\n\n ## Description\n \#{description}\n\n ## Detailed Outline\n \#{arc_outline}\n\n ---\n *Created: \#{Time.now}*\n MARKDOWN\n\n {\n name: arc_name,\n outline: arc_outline,\n saved_to: arc_path\n }\nend\n") |
#develop_character(name, basic_info = {}, chat: false) ⇒ Object
Develop a character profile from basic information
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 |
# File 'lib/writers_room/writer.rb', line 70 def develop_character(name, basic_info = {}, chat: false) personality = basic_info[:personality] || basic_info["personality"] || "to be determined" background = basic_info[:background] || basic_info["background"] || "" if chat chat_result = chat_about_character(name, personality, background) return chat_result if chat_result end @robot.update( template: :develop_character, context: { project_concept: .concept, character_name: name, personality: personality, background: background } ) result = @robot.run("Create a detailed character profile for #{name}.") character_profile = result.reply dev_path = File.join(@project_path, "characters", "#{sanitize_filename(name)}_development.md") FileUtils.mkdir_p(File.dirname(dev_path)) File.write(dev_path, " # Character Profile: \#{name}\n\n \#{character_profile}\n\n ---\n *Generated: \#{Time.now}*\n *Based on: \#{personality}*\n MARKDOWN\n\n {\n name: name,\n profile: character_profile,\n saved_to: dev_path\n }\nend\n") |
#develop_concept(chat: false) ⇒ Object
Develop the project concept into a fuller description using LLM
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 |
# File 'lib/writers_room/writer.rb', line 29 def develop_concept(chat: false) current_concept = .concept if chat chat_result = chat_about_concept(current_concept) return chat_result if chat_result end if current_concept.empty? raise Error, "No concept found. Initialize project with a concept first, or use --chat to develop one interactively." end @robot.update( template: :develop_concept, context: { concept: current_concept } ) result = @robot.run("Develop this concept into a fuller project description.") developed_concept = result.reply notes_path = File.join(@project_path, "concept_development.md") File.write(notes_path, " # Project Concept Development\n\n ## Original Concept\n \#{current_concept}\n\n ## Developed Concept\n \#{developed_concept}\n\n *Generated: \#{Time.now}*\n MARKDOWN\n\n {\n original: current_concept,\n developed: developed_concept,\n saved_to: notes_path\n }\nend\n") |