Agents + bash
diff --git a/loop/agent.go b/loop/agent.go
index 8e903a2..bd7c0d2 100644
--- a/loop/agent.go
+++ b/loop/agent.go
@@ -15,35 +15,68 @@
func (a *UserAgent) Run(todo *ToDo) error {
for {
+ unlocked := false
+ todo.Lock()
items := findActionableItems(todo, "user")
if len(items) == 0 {
+ fmt.Println("## USER NO ITEMS")
+ todo.Unlock()
time.Sleep(30 * time.Second)
continue
}
+ fmt.Println(todo.String())
+ fmt.Printf("-- YOU START WORKING %d\n", len(items))
for _, i := range items {
fmt.Printf("YOU %s %s: ", i.ID, i.Title)
comment, err := a.pr.Read()
if err != nil {
return err
}
+ if comment == "DONE" {
+ i.Done = true
+ continue
+ }
+ if comment == "BREAK" {
+ unlocked = true
+ todo.Unlock()
+ time.Sleep(30 * time.Second)
+ break
+ }
+ if comment == "ASSIGN" {
+ i.AssignedTo = "assistant"
+ continue
+ }
i.Discussion = append(i.Discussion, Comment{
Author: "user",
Comment: comment,
})
i.AssignedTo = "assistant"
}
+ fmt.Println("-- YOU END WORKING")
+ if !unlocked {
+ todo.Unlock()
+ }
}
}
func findActionableItems(todo *ToDo, assignedTo string) []*ToDo {
+ if todo.Done {
+ return nil
+ }
+ var ret []*ToDo
for _, i := range todo.Items {
- ret := findActionableItems(i, assignedTo)
- if len(ret) > 0 {
+ ret = append(ret, findActionableItems(i, assignedTo)...)
+ if len(ret) > 0 && !todo.Parallel {
return ret
}
}
- if todo.AssignedTo == assignedTo && !todo.Done {
+ if len(ret) == 0 && todo.AssignedTo == assignedTo && !todo.Done {
+ for _, i := range todo.Items {
+ if !i.Done {
+ return nil
+ }
+ }
return []*ToDo{todo}
}
- return nil
+ return ret
}