@@ -5,18 +5,29 @@ require 'json'
55require 'optparse'
66require '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+
815def 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
5364end
5465
5566class 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
116149end
@@ -166,11 +199,6 @@ class UpdateTask
166199 end
167200end
168201
169- LOOP_COMMAND = "loop"
170- NEXT_COMMAND = "next-task"
171- UPDATE_COMMAND = "update-task"
172- HELP_COMMAND = "help"
173-
174202command = ARGV . shift
175203
176204case 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!
186216when NEXT_COMMAND
187217 next_options = parsed_next_options
0 commit comments