session

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package session provides conversation persistence with save, resume, and fork capabilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("session not found")

ErrNotFound is returned by Find when no session matches the given prefix.

Functions

This section is empty.

Types

type ListResult

type ListResult struct {
	Summaries []Summary
	Warnings  []string
}

ListResult holds session summaries and any warnings encountered during listing.

type Manager

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

Manager orchestrates session save, resume, and fork operations.

func NewManager

func NewManager(store *Store) *Manager

NewManager creates a Manager backed by the given Store.

func (*Manager) ActiveID

func (m *Manager) ActiveID() string

ActiveID returns the ID of the active session, or the pending name, or empty string.

func (*Manager) ActiveTitle

func (m *Manager) ActiveTitle() string

ActiveTitle returns the title of the current active session, or empty string.

func (*Manager) Find

func (m *Manager) Find(prefix string) (string, error)

Find resolves a session ID prefix to a full session ID.

func (*Manager) Fork

func (m *Manager) Fork()

Fork clears the active session so the next Save creates a new one.

func (*Manager) List

func (m *Manager) List() (ListResult, error)

List returns all stored session summaries along with any warnings about corrupt or unreadable session files.

func (*Manager) ListDisplay

func (m *Manager) ListDisplay() (string, error)

ListDisplay returns a formatted string of all sessions for display.

func (*Manager) Resume

func (m *Manager) Resume(id string) (*Session, error)

Resume loads a session by ID and sets it as the active session.

func (*Manager) Save

func (m *Manager) Save(title string, meta Meta, msgs message.Messages, todos *todo.List) (*Session, error)

Save persists the current conversation state. If a session is already active (previously saved or resumed), it updates that session; otherwise creates a new one.

func (*Manager) SetName

func (m *Manager) SetName(name string) error

SetName assigns a custom name (ID) to the current or next session. For unsaved sessions, the name is stored eagerly and used by the next Save. For saved sessions, the file is renamed on disk.

type Meta

type Meta struct {
	Agent            string                 `json:"agent"`
	Mode             string                 `json:"mode"`
	Think            string                 `json:"think"`
	Model            string                 `json:"model,omitempty"`
	Provider         string                 `json:"provider,omitempty"`
	Verbose          bool                   `json:"verbose,omitempty"`
	LoadedTools      []string               `json:"loaded_tools,omitempty"`
	ReadBeforePolicy *tool.ReadBeforePolicy `json:"read_before_policy,omitempty"`

	// Runtime toggles
	Sandbox bool `json:"sandbox,omitempty"`

	// Session-scoped state
	SessionApprovals map[string]bool `json:"session_approvals,omitempty"`
	Stats            *stats.Stats    `json:"stats,omitempty"`
	CumulativeUsage  *usage.Usage    `json:"cumulative_usage,omitempty"`
}

Meta captures the assistant state at the time of save.

type Session

type Session struct {
	ID        string           `json:"id"`
	Title     string           `json:"title"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
	Messages  message.Messages `json:"messages"`
	Meta      Meta             `json:"meta"`
	Todos     *todo.List       `json:"todos,omitempty"`
}

Session is a complete conversation snapshot.

func (Session) FirstUserContent

func (s Session) FirstUserContent() string

FirstUserContent returns the content of the first real user message, or empty string. Excludes internal types (DisplayOnly, Bookmark, Metadata).

func (Session) IsUUID

func (s Session) IsUUID() bool

IsUUID reports whether the session ID is a UUID (as opposed to a user-chosen name).

func (Session) ShortDisplay

func (s Session) ShortDisplay() string

ShortDisplay returns a brief session identifier. Custom names are shown in full; UUIDs are truncated to 8 characters.

type Store

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

Store handles JSON file-based session persistence.

func NewStore

func NewStore(dir string) *Store

NewStore creates a Store rooted at the given directory.

func (*Store) Exists

func (s *Store) Exists(id string) bool

Exists reports whether a session with the given ID exists on disk.

func (*Store) Find

func (s *Store) Find(prefix string) (string, error)

Find resolves a session ID prefix to a full session ID. Returns an error if zero or multiple sessions match.

func (*Store) List

func (s *Store) List() (ListResult, error)

List returns summaries of all sessions, sorted newest first. Corrupt or unreadable session files are reported as warnings rather than causing the entire listing to fail.

func (*Store) Load

func (s *Store) Load(id string) (*Session, error)

Load reads a session from disk by ID.

func (*Store) Path

func (s *Store) Path(id string) file.File

func (*Store) Read

func (s *Store) Read(f file.File) (*Session, error)

func (*Store) Rename

func (s *Store) Rename(oldID, newID string) error

Rename changes a session's file name on disk from oldID to newID.

func (*Store) Save

func (s *Store) Save(session *Session) error

Save writes a session to disk as JSON.

type Summary

type Summary struct {
	ID               string    `json:"id"`
	Title            string    `json:"title"`
	UpdatedAt        time.Time `json:"updated_at"`
	FirstUserMessage string    `json:"first_user_message"`
}

Summary is a lightweight listing entry for a session.

func (Summary) Display

func (s Summary) Display() string

Display formats the summary for human-readable output.

func (Summary) IsUUID

func (s Summary) IsUUID() bool

IsUUID reports whether the session ID is a UUID (as opposed to a user-chosen name).

func (Summary) PickerDescription

func (s Summary) PickerDescription() string

PickerDescription returns secondary text for a picker item. Shows a humanized relative time and the short session ID.

func (Summary) PickerLabel

func (s Summary) PickerLabel() string

PickerLabel returns the main display text for a picker item. Shows the title if set, otherwise falls back to a truncated first user message.

func (Summary) ShortID

func (s Summary) ShortID() string

ShortID returns a display-friendly version of the ID. Custom names are shown in full; UUIDs are truncated to 8 characters.

Jump to

Keyboard shortcuts

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