Class: Ralph::Storage::State
- Inherits:
-
Object
- Object
- Ralph::Storage::State
- Defined in:
- lib/ralph/storage/state.rb
Overview
Represents and persists Ralph loop state
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#completion_promise ⇒ Object
readonly
Returns the value of attribute completion_promise.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#max_iterations ⇒ Object
readonly
Returns the value of attribute max_iterations.
-
#min_iterations ⇒ Object
readonly
Returns the value of attribute min_iterations.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#task_promise ⇒ Object
readonly
Returns the value of attribute task_promise.
-
#tasks_mode ⇒ Object
readonly
Returns the value of attribute tasks_mode.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(active:, iteration:, min_iterations:, max_iterations:, completion_promise:, tasks_mode:, task_promise:, prompt:, started_at:, model:, agent:) ⇒ State
constructor
A new instance of State.
- #save ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(active:, iteration:, min_iterations:, max_iterations:, completion_promise:, tasks_mode:, task_promise:, prompt:, started_at:, model:, agent:) ⇒ State
Returns a new instance of State.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ralph/storage/state.rb', line 15 def initialize(active:, iteration:, min_iterations:, max_iterations:, completion_promise:, tasks_mode:, task_promise:, prompt:, started_at:, model:, agent:) @active = active @iteration = iteration @min_iterations = min_iterations @max_iterations = max_iterations @completion_promise = completion_promise @tasks_mode = tasks_mode @task_promise = task_promise @prompt = prompt @started_at = started_at @model = model @agent = agent end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
10 11 12 |
# File 'lib/ralph/storage/state.rb', line 10 def active @active end |
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def agent @agent end |
#completion_promise ⇒ Object (readonly)
Returns the value of attribute completion_promise.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def completion_promise @completion_promise end |
#iteration ⇒ Object
Returns the value of attribute iteration.
10 11 12 |
# File 'lib/ralph/storage/state.rb', line 10 def iteration @iteration end |
#max_iterations ⇒ Object (readonly)
Returns the value of attribute max_iterations.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def max_iterations @max_iterations end |
#min_iterations ⇒ Object (readonly)
Returns the value of attribute min_iterations.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def min_iterations @min_iterations end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def model @model end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def prompt @prompt end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def started_at @started_at end |
#task_promise ⇒ Object (readonly)
Returns the value of attribute task_promise.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def task_promise @task_promise end |
#tasks_mode ⇒ Object (readonly)
Returns the value of attribute tasks_mode.
11 12 13 |
# File 'lib/ralph/storage/state.rb', line 11 def tasks_mode @tasks_mode end |
Class Method Details
.clear ⇒ Object
107 108 109 110 111 |
# File 'lib/ralph/storage/state.rb', line 107 def clear File.delete(path) if File.exist?(path) rescue StandardError # ignore end |
.dir ⇒ Object
77 78 79 |
# File 'lib/ralph/storage/state.rb', line 77 def dir File.join(Dir.pwd, '.ralph') end |
.from_config(config, prompt:) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ralph/storage/state.rb', line 59 def from_config(config, prompt:) new( iteration: 1, active: true, prompt: prompt.to_s, started_at: Time.now.utc.iso8601, model: config.model, agent: config.chosen_agent, tasks_mode: config.tasks_mode, task_promise: config.task_promise, min_iterations: config.min_iterations, max_iterations: config.max_iterations, completion_promise: config.completion_promise, ) end |
.load ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ralph/storage/state.rb', line 85 def load if File.exist?(path) JSON.parse(File.read(path)).then do |data| new( active: data['active'], iteration: data['iteration'], min_iterations: data['minIterations'], max_iterations: data['maxIterations'], completion_promise: data['completionPromise'], tasks_mode: data['tasksMode'], task_promise: data['taskPromise'], prompt: data['prompt'], started_at: data['startedAt'], model: data['model'], agent: data['agent'] ) end end rescue StandardError nil end |
.path ⇒ Object
81 82 83 |
# File 'lib/ralph/storage/state.rb', line 81 def path File.join(dir, 'ralph-loop.state.json') end |
Instance Method Details
#clear ⇒ Object
36 37 38 39 40 |
# File 'lib/ralph/storage/state.rb', line 36 def clear File.delete(self.class.path) if File.exist?(self.class.path) rescue StandardError # ignore end |
#save ⇒ Object
31 32 33 34 |
# File 'lib/ralph/storage/state.rb', line 31 def save FileUtils.mkdir_p(self.class.dir) File.write(self.class.path, JSON.pretty_generate(to_h)) end |
#to_h ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ralph/storage/state.rb', line 42 def to_h { active: @active, iteration: @iteration, minIterations: @min_iterations, maxIterations: @max_iterations, completionPromise: @completion_promise, tasksMode: @tasks_mode, taskPromise: @task_promise, prompt: @prompt, startedAt: @started_at, model: @model, agent: @agent } end |