| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "strings" |
| 7 | |
| 8 | goaldomain "reasonix/internal/goal" |
| 9 | ) |
| 10 | |
| 11 | // EditGoalDurable edits the current v3 Goal without replacing its identity or |
| 12 | // resetting admitted rounds. A nil limit explicitly selects unlimited rounds. |
| 13 | func (c *Controller) EditGoalDurable(objective string, maxGoalRounds *uint64) error { |
| 14 | if !c.sessionEngineEnabled() { |
| 15 | return errors.New("editing a goal in place requires a linear v3 session") |
| 16 | } |
| 17 | current, err := c.goalLifecycleView() |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | if current == nil { |
| 22 | return errors.New("no goal is available to edit") |
| 23 | } |
| 24 | objective = strings.TrimSpace(objective) |
| 25 | _, err = c.applyHostGoalMutation(context.Background(), "edit", func(machine *goaldomain.Machine) (*goaldomain.View, error) { |
| 26 | edited, editErr := machine.Edit(current.Ref(), goaldomain.EditRequest{ |
| 27 | Objective: &objective, |
| 28 | MaxGoalRounds: goaldomain.RoundLimitChange{Set: true, Value: maxGoalRounds}, |
| 29 | }) |
| 30 | return &edited, editErr |
| 31 | }) |
| 32 | if err == nil && current.Phase == goaldomain.PhaseActive && current.Activation == goaldomain.ActivationArmed { |
| 33 | c.kickGoalDriver() |
| 34 | } |
| 35 | return err |
| 36 | } |
| 37 |