session

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package session provides persistent conversation storage using JSONL files. Each session is a file in XDG_DATA_HOME/ai-cli/sessions/<id>.jsonl. The first line is metadata; subsequent lines are messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendMessage

func AppendMessage(sess *Session, msg provider.Message) error

AppendMessage adds a message to an existing session file and updates metadata.

func DataDir

func DataDir() string

DataDir returns the session storage directory, respecting XDG_DATA_HOME.

func Delete

func Delete(id string) error

Delete removes a session file.

func NewID

func NewID() string

NewID returns an 8-character hex string derived from the current time.

func Save

func Save(sess *Session) error

Save writes a session as a JSONL file (metadata line + message lines).

func Truncate

func Truncate(s string, maxLen int) string

Truncate shortens s to maxLen characters, adding "..." if truncated.

Types

type Metadata

type Metadata struct {
	ID           string    `json:"id"`
	Title        string    `json:"title"`
	Provider     string    `json:"provider"`      // registry key: "ollama"
	ProviderName string    `json:"provider_name"` // display name: "Ollama"
	Model        string    `json:"model"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	Messages     int       `json:"messages"`
}

Metadata describes a saved session.

func List

func List() ([]Metadata, error)

List returns metadata for all saved sessions, sorted by UpdatedAt descending.

type Session

type Session struct {
	Meta     Metadata           `json:"meta"`
	Messages []provider.Message `json:"messages"`
}

Session holds metadata and the full message history.

func Load

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

Load reads a session from its JSONL file.

Jump to

Keyboard shortcuts

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