session

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinNameLength is the minimum allowed session name length
	MinNameLength = 2

	// MaxNameLength is the maximum allowed session name length
	MaxNameLength = 64
)

Variables

View Source
var (

	// ErrInvalidName is returned when session name validation fails
	ErrInvalidName = errors.New("invalid session name")
)

Functions

func ValidateName

func ValidateName(name string) error

ValidateName checks if a session name is valid. Returns an error if the name is invalid, with details about why.

Types

type FileStore

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore implements Store using the filesystem.

func NewFileStore

func NewFileStore(clotildeRoot string) *FileStore

NewFileStore creates a new FileStore.

func (*FileStore) Create

func (fs *FileStore) Create(session *Session) error

Create creates a new session folder structure with metadata.

func (*FileStore) Delete

func (fs *FileStore) Delete(name string) error

Delete removes a session folder and all its contents.

func (*FileStore) Exists

func (fs *FileStore) Exists(name string) bool

Exists checks if a session exists.

func (*FileStore) Get

func (fs *FileStore) Get(name string) (*Session, error)

Get retrieves a session by name.

func (*FileStore) List

func (fs *FileStore) List() ([]*Session, error)

List returns all sessions, sorted by lastAccessed (most recent first).

func (*FileStore) LoadSettings

func (fs *FileStore) LoadSettings(name string) (*Settings, error)

LoadSettings loads settings.json for a session (returns nil if not exists).

func (*FileStore) LoadSystemPrompt

func (fs *FileStore) LoadSystemPrompt(name string) (string, error)

LoadSystemPrompt loads system-prompt.md for a session (returns empty if not exists).

func (*FileStore) SaveSettings

func (fs *FileStore) SaveSettings(name string, settings *Settings) error

SaveSettings saves settings.json for a session.

func (*FileStore) SaveSystemPrompt

func (fs *FileStore) SaveSystemPrompt(name string, content string) error

SaveSystemPrompt saves system-prompt.md for a session.

func (*FileStore) Update

func (fs *FileStore) Update(session *Session) error

Update updates session metadata.

type Metadata

type Metadata struct {
	Name                 string    `json:"name"`
	SessionID            string    `json:"sessionId"`
	TranscriptPath       string    `json:"transcriptPath,omitempty"`
	Created              time.Time `json:"created"`
	LastAccessed         time.Time `json:"lastAccessed"`
	ParentSession        string    `json:"parentSession,omitempty"`
	IsForkedSession      bool      `json:"isForkedSession"`
	IsIncognito          bool      `json:"isIncognito"`
	PreviousSessionIDs   []string  `json:"previousSessionIds,omitempty"`
	SystemPromptMode     string    `json:"systemPromptMode,omitempty"` // "append" (default) or "replace"
	HasCustomOutputStyle bool      `json:"hasCustomOutputStyle,omitempty"`
}

Metadata represents the session metadata stored in metadata.json.

func (*Metadata) GetSystemPromptMode

func (m *Metadata) GetSystemPromptMode() string

GetSystemPromptMode returns the system prompt mode ("append" or "replace"). Returns empty string if not set.

type Permissions

type Permissions struct {
	Allow                        []string `json:"allow,omitempty"`
	Ask                          []string `json:"ask,omitempty"`
	Deny                         []string `json:"deny,omitempty"`
	AdditionalDirectories        []string `json:"additionalDirectories,omitempty"`
	DefaultMode                  string   `json:"defaultMode,omitempty"`
	DisableBypassPermissionsMode string   `json:"disableBypassPermissionsMode,omitempty"`
}

Permissions represents the permissions configuration for a session.

type Session

type Session struct {
	Name     string
	Metadata Metadata
}

Session represents a named Claude Code session.

func NewForkedSession

func NewForkedSession(name, parentName string) *Session

NewForkedSession creates a new forked session with empty sessionId. The sessionId will be filled in later by the session-start hook.

func NewIncognitoSession

func NewIncognitoSession(name, sessionID string) *Session

NewIncognitoSession creates a new incognito session that will auto-delete on exit.

func NewSession

func NewSession(name, sessionID string) *Session

NewSession creates a new session with the given name and UUID.

func (*Session) AddPreviousSessionID

func (s *Session) AddPreviousSessionID(newSessionID string)

AddPreviousSessionID appends the current session ID to the history and updates to the new ID. This is idempotent - won't add duplicates.

func (*Session) UpdateLastAccessed

func (s *Session) UpdateLastAccessed()

UpdateLastAccessed updates the lastAccessed timestamp to now.

type Settings

type Settings struct {
	Model       string      `json:"model,omitempty"`
	OutputStyle string      `json:"outputStyle,omitempty"`
	Permissions Permissions `json:"permissions,omitempty"`
}

Settings represents Claude Code session-specific settings stored in settings.json.

type Store

type Store interface {
	// List returns all sessions, sorted by lastAccessed (most recent first)
	List() ([]*Session, error)

	// Get retrieves a session by name
	Get(name string) (*Session, error)

	// Create creates a new session folder structure with metadata
	Create(session *Session) error

	// Update updates session metadata
	Update(session *Session) error

	// Delete removes a session folder and all its contents
	Delete(name string) error

	// Exists checks if a session exists
	Exists(name string) bool

	// LoadSettings loads settings.json for a session (returns nil if not exists)
	LoadSettings(name string) (*Settings, error)

	// SaveSettings saves settings.json for a session
	SaveSettings(name string, settings *Settings) error

	// LoadSystemPrompt loads system-prompt.md for a session (returns empty if not exists)
	LoadSystemPrompt(name string) (string, error)

	// SaveSystemPrompt saves system-prompt.md for a session
	SaveSystemPrompt(name string, content string) error
}

Store defines the interface for session storage operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL