storage

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package storage manages persisted conversation metadata.

Index

Constants

View Source
const (
	// SHA1Short is the short display length used in CLI output.
	SHA1Short = 7
	// SHA1MinLen is the minimum prefix length considered for ID matching.
	SHA1MinLen = 4
	// SHA1ReadBlockSize is the size of random bytes mixed into ID generation.
	SHA1ReadBlockSize = 4096
)

Variables

View Source
var (
	// ErrNoMatches is returned when no conversations match the query.
	ErrNoMatches = errors.New("no conversations found")
	// ErrManyMatches is returned when multiple conversations match the query.
	ErrManyMatches = errors.New("multiple conversations matched the input")
)
View Source
var SHA1Regexp = regexp.MustCompile(`\b[0-9a-f]{40}\b`)

SHA1Regexp matches a full 40-char SHA-1 hex string.

Functions

func NewConversationID

func NewConversationID() string

NewConversationID generates a stable-looking ID for conversation records.

This is not used for cryptographic security; it is used as an identifier.

Types

type Conversation

type Conversation struct {
	ID        string    `db:"id"`
	Title     string    `db:"title"`
	UpdatedAt time.Time `db:"updated_at"`
	API       *string   `db:"api"`
	Model     *string   `db:"model"`
}

Conversation in the database.

type DB

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

DB is an append-only JSONL-backed conversation metadata index.

func Open

func Open(ds string) (*DB, error)

Open loads the conversation metadata store from the given datasource.

The datasource is usually a directory path. The special value ":memory:" creates a temporary store (primarily used for tests).

func (*DB) Close

func (c *DB) Close() error

Close releases temporary resources (used for :memory: stores).

func (*DB) Completions

func (c *DB) Completions(in string) []string

Completions returns shell completion candidates for IDs and titles.

func (*DB) Delete

func (c *DB) Delete(id string) error

Delete removes a conversation record by ID.

func (*DB) Find

func (c *DB) Find(in string) (*Conversation, error)

Find resolves a conversation by ID prefix or exact title.

func (*DB) FindHEAD

func (c *DB) FindHEAD() (*Conversation, error)

FindHEAD returns the most recently updated conversation.

func (*DB) List

func (c *DB) List() []Conversation

List returns conversations sorted by most recently updated.

func (*DB) ListOlderThan

func (c *DB) ListOlderThan(t time.Duration) []Conversation

ListOlderThan returns conversations older than the given duration.

func (*DB) Save

func (c *DB) Save(id, title, api, model string) error

Save upserts a conversation metadata record.

Directories

Path Synopsis
Package cache provides a simple in-file cache implementation.
Package cache provides a simple in-file cache implementation.

Jump to

Keyboard shortcuts

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