session

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultKeepRecentMessages = 20
	MinKeepRecentMessages     = 5
	MaxKeepRecentMessages     = 200
	DefaultKeepRecentTokens   = 12000
	MinKeepRecentTokens       = 1
	MaxKeepRecentTokens       = 64000
)

Variables

This section is empty.

Functions

func AppendMessage

func AppendMessage(path string, msg Message) error

AppendMessage appends a single message as one JSON line to the JSONL file at path.

func BuildCompactionSummary

func BuildCompactionSummary(messages []Message) string

func EstimateTokens

func EstimateTokens(messages []Message) int

func RewriteMessages

func RewriteMessages(path string, messages []Message) error

RewriteMessages replaces the transcript contents with the provided messages.

Types

type CompactOptions

type CompactOptions struct {
	BeforeRewrite    func(summary string, compactedCount int, originalCount int) error
	SummaryBuilder   func(messages []Message) (string, error)
	KeepRecentTokens int
}

type CompactResult

type CompactResult struct {
	Compacted      bool
	OriginalCount  int
	FinalCount     int
	CompactedCount int
	Summary        string
}

func CompactTranscript

func CompactTranscript(path string, keepRecent int, now time.Time) (CompactResult, error)

func CompactTranscriptWithOptions

func CompactTranscriptWithOptions(path string, keepRecent int, now time.Time, opts CompactOptions) (CompactResult, error)

type HistorySnapshot

type HistorySnapshot struct {
	Messages       []Message
	Tokens         int
	CompactionUsed bool
}

HistorySnapshot captures the portion of transcript loaded into model context.

func LoadHistorySnapshot

func LoadHistorySnapshot(path string, maxTokens int) (HistorySnapshot, error)

LoadHistorySnapshot reads transcript history and returns the loaded messages together with token and compaction-boundary metadata.

type Message

type Message struct {
	Role      string    `json:"role"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

Message represents a single chat message in a session transcript.

func LoadHistory

func LoadHistory(path string, maxTokens int) ([]Message, error)

LoadHistory reads messages from a JSONL file, returning only the most recent messages that fit within the given token budget. Tokens are estimated as len(content)/4. Messages are returned in chronological order (oldest first). Returns an empty slice if the file does not exist.

func ReadMessages

func ReadMessages(path string) ([]Message, error)

ReadMessages reads all messages from a JSONL file. Returns an empty slice if the file does not exist or is empty.

type Session

type Session struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	Kind      string    `json:"kind,omitempty"`
	Hidden    bool      `json:"hidden,omitempty"`
	ProjectID string    `json:"project_id,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Store

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

func NewStore

func NewStore(dir string) *Store

func (*Store) Create

func (s *Store) Create(title string) (Session, error)

func (*Store) CreateWithOptions

func (s *Store) CreateWithOptions(title string, kind string, hidden bool) (Session, error)

func (*Store) Delete

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

func (*Store) EnsureMain

func (s *Store) EnsureMain() (Session, error)

func (*Store) EnsureWorker

func (s *Store) EnsureWorker(projectID string) (Session, error)

func (*Store) Get

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

func (*Store) Latest

func (s *Store) Latest() (Session, error)

func (*Store) LatestAll

func (s *Store) LatestAll() (Session, error)

func (*Store) List

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

func (*Store) ListAll

func (s *Store) ListAll() ([]Session, error)

func (*Store) SetProjectID

func (s *Store) SetProjectID(id string, projectID string) error

func (*Store) Touch

func (s *Store) Touch(id string, updatedAt time.Time) error

func (*Store) TranscriptPath

func (s *Store) TranscriptPath(id string) string

func (*Store) WorkspaceDir

func (s *Store) WorkspaceDir() string

Jump to

Keyboard shortcuts

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