Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: EUPL-1.2 Imports: 16 Imported by: 0

Documentation

Overview

Package session persists a session's events as redacted JSONL and reloads them.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidID = errors.New("invalid session id")

ErrInvalidID means a session ID is not of the form s_<12 hex digits>.

View Source
var ErrLocked = errors.New("session already open")

ErrLocked means another process (or writer) already holds the session.

View Source
var ErrNoSession = errors.New("no session found")

ErrNoSession means no matching session exists.

Functions

func Exists

func Exists(dir, sessionID string) error

Exists reports ErrInvalidID for a malformed ID and ErrNoSession when <dir>/<sessionID>.jsonl does not exist; it creates nothing.

func Latest

func Latest(dir, projectRoot string) (string, error)

Latest returns the ID of the most recent session of projectRoot.

func Load

func Load(dir, sessionID string) (events []event.Event, corrupt bool, err error)

Load reads a session. It stops at the first unreadable line, returning the valid events so far and corrupt=true. A missing file gives ErrNoSession.

func SameRoot

func SameRoot(a, b string) bool

SameRoot reports whether two project roots designate the same directory: paths are cleaned and symlinks resolved when possible. An empty root never matches.

Types

type Lock

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

Lock is a held session lock. It is taken before reading a session to resume, so that no other process writes it meanwhile, then handed over to the Writer by Open.

func Acquire

func Acquire(dir, sessionID string) (*Lock, error)

Acquire creates dir (0700) and takes the session's lock (ErrLocked if another process or writer holds it).

func (*Lock) Open

func (l *Lock) Open(redact func(string) string) (*Writer, error)

Open repairs the session file (see repair) and opens it in append mode; the returned Writer owns the lock. On error the lock is still held.

func (*Lock) Release

func (l *Lock) Release()

Release drops the lock if it was not handed over to a Writer.

type Summary

type Summary struct {
	ID, ProjectRoot, FirstPrompt string
	Updated                      time.Time
	Turns                        int
}

Summary describes a stored session.

func List

func List(dir, projectRoot string) ([]Summary, error)

List returns the sessions of projectRoot, most recent first. Unreadable sessions are skipped. A missing dir gives an empty list.

type Writer

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

Writer appends one redacted, fsynced JSON line per event of its session. Safe for concurrent use.

func Open

func Open(dir, sessionID string, redact func(string) string) (*Writer, error)

Open creates dir (0700) and opens <dir>/<sessionID>.jsonl (0600) in append mode, so an existing session is continued. A nil redact is the identity.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the file.

func (*Writer) Write

func (w *Writer) Write(e event.Event) error

Write persists e. Events of other sessions and AssistantDelta are ignored.

Jump to

Keyboard shortcuts

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