session

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package session provides read-only SQLite access to opencode's local session store at $XDG_DATA_HOME/opencode/opencode.db. It is used by the public StatSession helper to surface session metadata without spinning up a Client.

Index

Constants

View Source
const DatabaseFile = "opencode.db"

DatabaseFile is the filename opencode writes its SQLite store to, relative to the opencode data directory ($XDG_DATA_HOME/opencode).

Variables

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

ErrNotFound is returned when a session row is missing or the database file does not exist on disk.

Functions

func DatabasePath

func DatabasePath(opencodeDataDir string) string

DatabasePath returns the opencode DB path given the opencode data directory (the directory that would contain opencode.db).

Types

type ListOptions

type ListOptions struct {
	// Cwd, when non-empty, restricts rows to those whose directory
	// matches exactly.
	Cwd string

	// IncludeArchived, when false, excludes rows with a non-null
	// time_archived.
	IncludeArchived bool

	// Limit caps the number of returned rows. Zero or negative means
	// no limit.
	Limit int
}

ListOptions controls the shape of a List result.

type Row

type Row struct {
	ID               string
	ProjectID        string
	ParentID         string
	Slug             string
	Directory        string
	Title            string
	Version          string
	ShareURL         string
	SummaryAdditions *int64
	SummaryDeletions *int64
	SummaryFiles     *int64
	CreatedAt        time.Time
	UpdatedAt        time.Time
	CompactingAt     *time.Time
	ArchivedAt       *time.Time
	WorkspaceID      string
	MessageCount     int64
}

Row mirrors the subset of opencode's `session` table that the SDK surfaces to callers, plus a joined message count.

func List

func List(ctx context.Context, dbPath string, opts ListOptions) ([]*Row, error)

List reads every session row from the local SQLite store, subject to opts. Rows are ordered by time_updated DESC so the most recently touched sessions come first. Missing database files yield ErrNotFound to mirror Lookup's semantics.

func Lookup

func Lookup(ctx context.Context, dbPath, sessionID, cwd string) (*Row, error)

Lookup reads the session row keyed by sessionID. When cwd is non-empty, results are additionally filtered by exact session.directory match.

Jump to

Keyboard shortcuts

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