| 1 | package checkpoint |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | func shouldTruncateConversation(tx *TransactionManifest) bool { |
| 6 | if tx == nil || tx.ConversationAction == "fork" { |
| 7 | return false |
| 8 | } |
| 9 | return tx.Scope == RewindConversation || tx.Scope == RewindBoth |
| 10 | } |
| 11 | |
| 12 | func (s *Store) PeekPlan(planID string) (RewindPlan, bool) { |
| 13 | if s == nil { |
| 14 | return RewindPlan{}, false |
| 15 | } |
| 16 | s.mu.Lock() |
| 17 | defer s.mu.Unlock() |
| 18 | pp, ok := s.plans[planID] |
| 19 | if !ok { |
| 20 | return RewindPlan{}, false |
| 21 | } |
| 22 | return pp.plan, true |
| 23 | } |
| 24 | |
| 25 | func (s *Store) MarkPlanConversationFork(planID string) { |
| 26 | if s == nil { |
| 27 | return |
| 28 | } |
| 29 | s.mu.Lock() |
| 30 | defer s.mu.Unlock() |
| 31 | pp, ok := s.plans[planID] |
| 32 | if !ok { |
| 33 | return |
| 34 | } |
| 35 | pp.plan.ConversationAction = "fork" |
| 36 | s.plans[planID] = pp |
| 37 | } |
| 38 | |
| 39 | func (s *Store) DiscardPlan(planID string) error { |
| 40 | if s == nil { |
| 41 | return fmt.Errorf("checkpoints unavailable") |
| 42 | } |
| 43 | s.mu.Lock() |
| 44 | defer s.mu.Unlock() |
| 45 | if _, ok := s.plans[planID]; !ok { |
| 46 | return fmt.Errorf("unknown or expired plan %q", planID) |
| 47 | } |
| 48 | delete(s.plans, planID) |
| 49 | return nil |
| 50 | } |
| 51 |