| 1 | package agent |
| 2 | |
| 3 | // Executor-local mirror of the last committed todo/write in the current real |
| 4 | // user turn. Durable state and client projections come from the host event |
| 5 | // ledger; this mirror only gives a running executor immediate semantic access. |
| 6 | |
| 7 | import ( |
| 8 | "reasonix/internal/evidence" |
| 9 | ) |
| 10 | |
| 11 | // SeedTodoState is a test/compatibility helper for constructing an in-memory |
| 12 | // executor projection. Production Plan and Goal paths never call it. |
| 13 | func (a *Agent) SeedTodoState(todos []evidence.TodoItem) { |
| 14 | if len(todos) == 0 { |
| 15 | return |
| 16 | } |
| 17 | a.setTodoState(todos) |
| 18 | } |
| 19 | |
| 20 | // ReplaceTodoState is retained for tests and compatibility callers that need to |
| 21 | // construct an executor-local projection. |
| 22 | func (a *Agent) ReplaceTodoState(todos []evidence.TodoItem) { |
| 23 | a.setTodoState(todos) |
| 24 | } |
| 25 | |
| 26 | // BeginTurnTodoState clears model-managed progress at the real host turn |
| 27 | // boundary. Mid-turn steering, approvals, compaction, and tool rounds do not |
| 28 | // call this method and therefore keep the last successful replacement. |
| 29 | func (a *Agent) BeginTurnTodoState() { |
| 30 | a.sess.todoMu.Lock() |
| 31 | a.sess.todoState = nil |
| 32 | a.sess.todoWritten = false |
| 33 | a.sess.todoMu.Unlock() |
| 34 | } |
| 35 | |
| 36 | // CanonicalTodoState returns a copy of the executor-local task list. |
| 37 | func (a *Agent) CanonicalTodoState() []evidence.TodoItem { |
| 38 | a.sess.todoMu.Lock() |
| 39 | defer a.sess.todoMu.Unlock() |
| 40 | return append([]evidence.TodoItem(nil), a.sess.todoState...) |
| 41 | } |
| 42 | |
| 43 | // TodoStateSnapshot returns one coherent semantic projection. TodoWritten is |
| 44 | // true after a successful current-turn write, including an explicit empty |
| 45 | // replacement. |
| 46 | func (a *Agent) TodoStateSnapshot() ([]evidence.TodoItem, bool) { |
| 47 | a.sess.todoMu.Lock() |
| 48 | defer a.sess.todoMu.Unlock() |
| 49 | return append([]evidence.TodoItem(nil), a.sess.todoState...), a.sess.todoWritten |
| 50 | } |
| 51 | |
| 52 | // CurrentTaskTodoState returns only the latest successful todo_write retained |
| 53 | // in the current evidence ledger. Unlike CanonicalTodoState, it never falls |
| 54 | // back to a prior user turn. |
| 55 | func (a *Agent) CurrentTaskTodoState() []evidence.TodoItem { |
| 56 | if a == nil || a.task.ledger == nil { |
| 57 | return nil |
| 58 | } |
| 59 | todos, ok := a.task.ledger.LatestTodos() |
| 60 | if !ok { |
| 61 | return nil |
| 62 | } |
| 63 | return append([]evidence.TodoItem(nil), todos...) |
| 64 | } |
| 65 |