Skip to content

Commit 5d2a839

Browse files
committed
Update ralph
1 parent 7754d2e commit 5d2a839

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

lib/scripts/ralph

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@ require 'json'
55
require 'optparse'
66
require 'open3'
77

8+
BASE_COMMAND = "ralph"
9+
LOOP_COMMAND = "loop"
10+
NEXT_COMMAND = "next-task"
11+
UPDATE_COMMAND = "update-task"
12+
HELP_COMMAND = "help"
13+
14+
815
def parsed_loop_options
916
options = {
1017
"model" => "opus",
1118
"completion_promise" => "ALLDONE",
1219
"max_iterations" => 100,
20+
"file" => 'ralph-tasks.json',
21+
"open_status" => 'open',
1322
}
1423

1524
OptionParser.new do |opts|
1625
opts.on('--prompt PROMPT', 'prompt') { |it| options["prompt"] = it }
1726
opts.on('--completion-promise COMPLETION_PROMISE', 'completion promise') { |it| options["completion_promise"] = it }
1827
opts.on('--max-iterations MAX_ITERATIONS', 'maximum iterations') { |it| options["max_iterations"] = it.to_i }
1928
opts.on('--model MODEL', 'model to use') { |it| options["model"] = it }
29+
opts.on('--file FILE', 'task file') { |it| options["file"] = it }
30+
opts.on('--open-status STATUS', 'status indicating open task') { |it| options["open_status"] = it }
2031
end.parse!
2132

2233
options
@@ -53,15 +64,24 @@ def parsed_update_options
5364
end
5465

5566
class Loop
56-
def initialize(prompt:, completion_promise:, max_iterations:, model:)
67+
def initialize(
68+
prompt:,
69+
completion_promise:,
70+
max_iterations:,
71+
model:,
72+
file:,
73+
open_status:
74+
)
5775
@prompt_file = prompt
5876
@completion_promise = completion_promise
5977
@max_iterations = max_iterations
6078
@model = model
6179
@iteration = 0
80+
@task_file = file
81+
@open_status = open_status
6282
end
6383

64-
attr_reader :completion_promise, :max_iterations, :iteration, :model, :prompt_file
84+
attr_reader :completion_promise, :max_iterations, :iteration, :model, :prompt_file, :task_file, :open_status
6585

6686
def run!
6787
puts <<~START
@@ -105,12 +125,25 @@ class Loop
105125
<<~PROMPT
106126
#{prompt_file}
107127
108-
## Tool reference
128+
## How to get the next task
129+
130+
When instructed to "get the next task" or something like that, you should run:
131+
132+
`#{BASE_COMMAND} #{NEXT_COMMAND} --file #{task_file} --open-status #{open_status}`
109133
110-
- `./ralph help` prints usage
111-
- `./ralph next-task` - returns JSON of the task to work on.
112-
- If it returns `'{ "_no_remaining_tasks": true }'`, that means no tasks remain to work on. Immediately exit
113-
- `./ralph update-task` - updates the status and data on a task. Use it to update tasks after you have attempted them.
134+
It will either return you a JSON object representing the next task to work on, or `'{ "_no_remaining_tasks": true }'` if there are no remaining tasks.
135+
136+
If you receive `'{ "_no_remaining_tasks": true }'`, output exactly #{completion_promise} and exit immediately.
137+
138+
## How to update a task
139+
140+
When instructed to "update the task" or something like that, you should run:
141+
142+
`#{BASE_COMMAND} #{UPDATE_COMMAND} --id <task_id> --status <new_status> --comment "<comments in quotes>" [--pull-request <pull_request>] --file #{task_file}`
143+
144+
## Tooling help
145+
146+
Running `#{BASE_COMMAND} #{HELP_COMMAND}` prints all available commands.
114147
PROMPT
115148
end
116149
end
@@ -166,11 +199,6 @@ class UpdateTask
166199
end
167200
end
168201

169-
LOOP_COMMAND = "loop"
170-
NEXT_COMMAND = "next-task"
171-
UPDATE_COMMAND = "update-task"
172-
HELP_COMMAND = "help"
173-
174202
command = ARGV.shift
175203

176204
case command
@@ -182,6 +210,8 @@ when LOOP_COMMAND
182210
completion_promise: loop_options.fetch("completion_promise"),
183211
max_iterations: loop_options.fetch("max_iterations"),
184212
model: loop_options.fetch("model"),
213+
file: loop_options.fetch("file"),
214+
open_status: loop_options.fetch("open_status"),
185215
).run!
186216
when NEXT_COMMAND
187217
next_options = parsed_next_options

0 commit comments

Comments
 (0)