session

package
v1.3.33 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentWorkspacePath added in v1.0.23

func CurrentWorkspacePath() string

func DefaultDir

func DefaultDir() (string, error)

DefaultDir returns the default session directory.

func ExportSessionMarkdown

func ExportSessionMarkdown(ses *Session) string

ExportSessionMarkdown renders a Session to markdown.

func NormalizeWorkspacePath added in v1.0.23

func NormalizeWorkspacePath(path string) string

Types

type JSONLStore

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

JSONLStore implements Store using JSONL files.

func NewDefaultStore

func NewDefaultStore() (*JSONLStore, error)

NewDefaultStore creates a store in the default directory.

func NewJSONLStore

func NewJSONLStore(dir string) (*JSONLStore, error)

NewJSONLStore creates a store rooted at dir (creates dir if needed).

func (*JSONLStore) AppendCheckpoint added in v1.1.43

func (s *JSONLStore) AppendCheckpoint(ses *Session, compactedMessages []provider.Message, tokenCount int) error

AppendCheckpoint appends a checkpoint record to the session JSONL file. The checkpoint captures the compacted messages state after a summarize operation, so that future --resume operations can skip re-compacting old history. AppendCheckpoint persists a checkpoint (compaction snapshot) to the session's JSONL file and updates the Session object in place. The caller must ensure no concurrent access to the Session object.

func (*JSONLStore) AppendCheckpointToDisk added in v1.1.60

func (s *JSONLStore) AppendCheckpointToDisk(ses *Session, compactedMessages []provider.Message, tokenCount int) error

AppendCheckpointToDisk persists a checkpoint to the session's JSONL file and updates the index, but does NOT modify the Session object. Use this when the caller manages Session mutations under its own lock and only needs the disk write to happen outside that lock.

func (*JSONLStore) AppendMessage

func (s *JSONLStore) AppendMessage(ses *Session, msg provider.Message) error

AppendMessage atomically appends a single message to the session's JSONL file. This is more efficient than Save() for incremental updates. AppendMessage persists a message to the session's JSONL file and updates the Session object in place (Messages, UpdatedAt, Title). The caller must ensure no concurrent access to the Session object.

func (*JSONLStore) AppendMessageToDisk added in v1.1.59

func (s *JSONLStore) AppendMessageToDisk(ses *Session, msg provider.Message) error

AppendMessageToDisk persists a message to the session's JSONL file and updates the index, but does NOT modify the Session object. Use this when the caller manages Session mutations under its own lock (e.g. sessionMutex in the TUI), and only needs the disk write to happen outside that lock.

func (*JSONLStore) AppendTunnelEventToDisk added in v1.3.20

func (s *JSONLStore) AppendTunnelEventToDisk(ses *Session, ev TunnelEvent) error

AppendTunnelEventToDisk persists a canonical tunnel event to the session's JSONL file and updates the index, but does NOT mutate the Session object.

func (*JSONLStore) CleanupOlderThan

func (s *JSONLStore) CleanupOlderThan(before time.Time) (int, error)

CleanupOlderThan removes sessions older than the given time. Returns count removed.

func (*JSONLStore) Delete

func (s *JSONLStore) Delete(id string) error

Delete removes a session file and its index entry.

func (*JSONLStore) Dir

func (s *JSONLStore) Dir() string

Dir returns the store's directory path.

func (*JSONLStore) EnsureMeta

func (s *JSONLStore) EnsureMeta(ses *Session) error

EnsureMeta writes the meta record if the session file doesn't exist yet. If the session has no user interaction, no file is created.

func (*JSONLStore) ExportMarkdown

func (s *JSONLStore) ExportMarkdown(id string) (string, error)

ExportMarkdown renders a session as a markdown document.

func (*JSONLStore) List

func (s *JSONLStore) List() ([]*Session, error)

List returns all sessions sorted by UpdatedAt descending (uses index for speed).

func (*JSONLStore) Load

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

Load reads a session from its JSONL file.

func (*JSONLStore) Save

func (s *JSONLStore) Save(ses *Session) error

Save writes the full session as a JSONL file (atomic). If the session has no user interaction, the file is deleted instead.

type Session

type Session struct {
	ID                   string             `json:"id"`
	CreatedAt            time.Time          `json:"created_at"`
	UpdatedAt            time.Time          `json:"updated_at"`
	Title                string             `json:"title"`
	Workspace            string             `json:"workspace,omitempty"`
	Vendor               string             `json:"vendor"`
	Endpoint             string             `json:"endpoint"`
	Model                string             `json:"model"`
	Messages             []provider.Message `json:"messages,omitempty"`
	TunnelEvents         []TunnelEvent      `json:"tunnel_events,omitempty"`
	TunnelEventsComplete bool               `json:"tunnel_events_complete,omitempty"`
	// Cost data stored as opaque JSON to avoid circular dependency with cost package.
	CostJSON []byte `json:"cost,omitempty"`
}

Session represents a single conversation session.

func NewSession

func NewSession(vendor, endpoint, model string) *Session

NewSession creates a new Session with a generated ID.

func (*Session) HasUserInteraction added in v1.1.50

func (s *Session) HasUserInteraction() bool

HasUserInteraction returns true if the session contains at least one user message with actual text content. Sessions without user interaction (e.g., created then immediately closed) should not be persisted to avoid accumulating empty session files.

type Store

type Store interface {
	// Save persists the current state of a session (atomic write).
	Save(s *Session) error

	// Load retrieves a session by ID.
	Load(id string) (*Session, error)

	// List returns all sessions, sorted by UpdatedAt descending.
	List() ([]*Session, error)

	// Delete removes a session by ID.
	Delete(id string) error

	// ExportMarkdown renders a session as a markdown document.
	ExportMarkdown(id string) (string, error)

	// CleanupOlderThan removes sessions whose UpdatedAt is before the given time.
	CleanupOlderThan(before time.Time) (int, error)

	// AppendCheckpoint persists a checkpoint of compacted messages after summarize.
	// The checkpoint allows --resume to skip re-compacting old history.
	AppendCheckpoint(s *Session, compactedMessages []provider.Message, tokenCount int) error
}

Store is the interface for session persistence.

type TunnelEvent added in v1.3.20

type TunnelEvent struct {
	EventID  string          `json:"event_id"`
	StreamID string          `json:"stream_id,omitempty"`
	Type     string          `json:"type"`
	Data     json.RawMessage `json:"data,omitempty"`
}

TunnelEvent is the canonical persisted tunnel event for a session.

Jump to

Keyboard shortcuts

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