MCPcopy Create free account
hub / github.com/diillson/chatcli / ForkSession

Method ForkSession

cli/session_manager.go:313–342  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
313func (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).
345func (sm *SessionManager) ForkCurrentToNew(newName string, sd *SessionData) error {

Callers 1

handleForkSessionMethod · 0.80

Calls 6

getSessionPathMethod · 0.95
LoadSessionV2Method · 0.95
SaveSessionV2Method · 0.95
ErrorfMethod · 0.80
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected