ForkSession creates a copy of an existing session with a new name. The forked session is an independent copy — changes to either session don't affect the other.
(sourceName, newName string)
| 311 | // ForkSession creates a copy of an existing session with a new name. |
| 312 | // The forked session is an independent copy — changes to either session don't affect the other. |
| 313 | func (sm *SessionManager) ForkSession(sourceName, newName string) error { |
| 314 | if sourceName == "" || newName == "" { |
| 315 | return fmt.Errorf("source and target session names required") |
| 316 | } |
| 317 | if sourceName == newName { |
| 318 | return fmt.Errorf("source and target names must be different") |
| 319 | } |
| 320 | |
| 321 | // Check target doesn't already exist |
| 322 | targetPath := sm.getSessionPath(newName) |
| 323 | if _, err := os.Stat(targetPath); err == nil { |
| 324 | return fmt.Errorf("sessão '%s' já existe, escolha outro nome", newName) |
| 325 | } |
| 326 | |
| 327 | // Load source |
| 328 | sd, err := sm.LoadSessionV2(sourceName) |
| 329 | if err != nil { |
| 330 | return fmt.Errorf("falha ao carregar sessão fonte: %w", err) |
| 331 | } |
| 332 | |
| 333 | // Save as new name |
| 334 | if err := sm.SaveSessionV2(newName, sd); err != nil { |
| 335 | return fmt.Errorf("falha ao salvar sessão fork: %w", err) |
| 336 | } |
| 337 | |
| 338 | sm.logger.Info("Session forked", |
| 339 | zap.String("source", sourceName), |
| 340 | zap.String("fork", newName)) |
| 341 | return nil |
| 342 | } |
| 343 | |
| 344 | // ForkCurrentToNew creates a fork from in-memory session data (for forking unsaved sessions). |
| 345 | func (sm *SessionManager) ForkCurrentToNew(newName string, sd *SessionData) error { |
no test coverage detected