| Sketch🕴️ | 305f817 | 2026-02-27 13:58:43 +0400 | [diff] [blame^] | 1 | package loop |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | type Agent interface { |
| 9 | Run(todo *ToDo) error |
| 10 | } |
| 11 | |
| 12 | type UserAgent struct { |
| 13 | pr PromptReader |
| 14 | } |
| 15 | |
| 16 | func (a *UserAgent) Run(todo *ToDo) error { |
| 17 | for { |
| 18 | items := findActionableItems(todo, "user") |
| 19 | if len(items) == 0 { |
| 20 | time.Sleep(30 * time.Second) |
| 21 | continue |
| 22 | } |
| 23 | for _, i := range items { |
| 24 | fmt.Printf("YOU %s %s: ", i.ID, i.Title) |
| 25 | comment, err := a.pr.Read() |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | i.Discussion = append(i.Discussion, Comment{ |
| 30 | Author: "user", |
| 31 | Comment: comment, |
| 32 | }) |
| 33 | i.AssignedTo = "assistant" |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func findActionableItems(todo *ToDo, assignedTo string) []*ToDo { |
| 39 | for _, i := range todo.Items { |
| 40 | ret := findActionableItems(i, assignedTo) |
| 41 | if len(ret) > 0 { |
| 42 | return ret |
| 43 | } |
| 44 | } |
| 45 | if todo.AssignedTo == assignedTo && !todo.Done { |
| 46 | return []*ToDo{todo} |
| 47 | } |
| 48 | return nil |
| 49 | } |