SetTasks replaces the entire plan with the supplied list. Used by the @todo plugin to mirror Claude Code's TodoWrite semantics: the LLM emits the full updated list every call; the tracker reconciles without preserving prior state. This is the only public path that lets a caller set per-task status
(specs []TaskSpec)
| 271 | // explicitly. MarkCurrentAs is for the per-turn ReAct flow (one task |
| 272 | // at a time); SetTasks is for the LLM-driven plan overwrite. |
| 273 | func (t *TaskTracker) SetTasks(specs []TaskSpec) { |
| 274 | t.mu.Lock() |
| 275 | defer t.mu.Unlock() |
| 276 | |
| 277 | tasks := make([]*Task, 0, len(specs)) |
| 278 | currentTask := 0 |
| 279 | for i, s := range specs { |
| 280 | status := s.Status |
| 281 | if status == "" { |
| 282 | status = TaskPending |
| 283 | } |
| 284 | tk := &Task{ |
| 285 | ID: i + 1, |
| 286 | Description: strings.TrimSpace(s.Description), |
| 287 | Status: status, |
| 288 | } |
| 289 | switch status { |
| 290 | case TaskInProgress: |
| 291 | tk.StartedAt = time.Now() |
| 292 | currentTask = i |
| 293 | case TaskCompleted: |
| 294 | tk.CompletedAt = time.Now() |
| 295 | } |
| 296 | tasks = append(tasks, tk) |
| 297 | } |
| 298 | |
| 299 | // Advance current marker past any prefix of completed tasks if no |
| 300 | // task was explicitly marked in_progress. This matches the ReAct |
| 301 | // loop's intuition that "next pending" is the current focus. |
| 302 | allInProgress := false |
| 303 | for _, s := range specs { |
| 304 | if s.Status == TaskInProgress { |
| 305 | allInProgress = true |
| 306 | break |
| 307 | } |
| 308 | } |
| 309 | if !allInProgress { |
| 310 | currentTask = 0 |
| 311 | for i, tk := range tasks { |
| 312 | if tk.Status != TaskCompleted { |
| 313 | currentTask = i |
| 314 | break |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | sig := strings.Join(func() []string { |
| 320 | parts := make([]string, 0, len(tasks)) |
| 321 | for _, tk := range tasks { |
| 322 | parts = append(parts, strings.ToLower(strings.TrimSpace(tk.Description))) |
| 323 | } |
| 324 | return parts |
| 325 | }(), "|") |
| 326 | |
| 327 | t.plan = &TaskPlan{ |
| 328 | Tasks: tasks, |
| 329 | CurrentTask: currentTask, |
| 330 | CreatedAt: time.Now(), |