Documentation
¶
Overview ¶
Package opencode reads sessions from OpenCode's SQLite store, satisfying the same source.Source contract as the claude backend.
The driver is ncruces/go-sqlite3 (pure Go) rather than a cgo driver, so the release pipeline keeps CGO_ENABLED=0 cross-compilation across all targets.
Index ¶
- Constants
- Variables
- func Preflight() error
- func ResolveDBPath() (path string, probed []string, err error)
- type DB
- func (d *DB) Close() error
- func (d *DB) FindByID(id string) (*session.Session, error)
- func (d *DB) GrepKeys(query string, regex bool) (map[string]struct{}, error)
- func (d *DB) Messages(sessionID string, limit int) (msgs []session.Message, startedAt time.Time, total int, err error)
- func (d *DB) Path() string
- func (d *DB) Scan() ([]*session.Session, error)
- func (d *DB) ScanFiltered(allow map[string]struct{}) ([]*session.Session, error)
Constants ¶
const EnvDBPath = "OPENCODE_DB"
EnvDBPath overrides database discovery with an explicit file path.
Variables ¶
var ErrDBNotFound = errors.New("opencode database not found")
Functions ¶
func Preflight ¶
func Preflight() error
Preflight resolves and opens the database before the TUI launches, so a missing DB, a pre-SQLite (legacy JSON) install, or an unreadable file fails on the normal terminal with an actionable message instead of invisibly inside fzf.
func ResolveDBPath ¶
ResolveDBPath returns the chosen database file, the locations it probed (for the not-found message), and ErrDBNotFound when nothing matched.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) FindByID ¶
FindByID returns the single session with the given id, or session.ErrSessionFileMissing when none matches (so preview/resume reuse the claude error handling).
func (*DB) GrepKeys ¶
GrepKeys returns the set of root session ids whose title or message text matches query. An empty query returns (nil, nil) to mean "no filtering", matching grep.Filter's contract.
A LIKE prefilter narrows the candidate sessions before the authoritative Go-side match. It is only an optimization, so it must never drop a real match: prefilterUsable disables it whenever LIKE could diverge from the matcher (regex, JSON-escapable chars, or a case fold the ASCII-only LIKE can't reproduce), in which case every root session is matched directly.
func (*DB) Messages ¶
func (d *DB) Messages(sessionID string, limit int) (msgs []session.Message, startedAt time.Time, total int, err error)
Messages returns up to limit of a session's most recent renderable turns in chronological order, plus the first turn's time and the total turn count for the preview header.
The session_message projection is read first; it falls back to the message +part store when the projection is empty of renderable turns or absent.