opencode

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
const EnvDBPath = "OPENCODE_DB"

EnvDBPath overrides database discovery with an explicit file path.

Variables

View Source
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

func ResolveDBPath() (path string, probed []string, err error)

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 Open

func Open() (*DB, error)

func (*DB) Close

func (d *DB) Close() error

func (*DB) FindByID

func (d *DB) FindByID(id string) (*session.Session, error)

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

func (d *DB) GrepKeys(query string, regex bool) (map[string]struct{}, error)

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.

func (*DB) Path

func (d *DB) Path() string

func (*DB) Scan

func (d *DB) Scan() ([]*session.Session, error)

func (*DB) ScanFiltered

func (d *DB) ScanFiltered(allow map[string]struct{}) ([]*session.Session, error)

ScanFiltered keeps only sessions whose id is in allow; nil allow keeps all.

Jump to

Keyboard shortcuts

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