sqlite

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite opens Hermes Agent's database, state.db, and reads its rows as the hermes package's types: sessions, messages, system_prompts, session_model_usage and async_delegations. It is one of the packages of this module that import a database driver, modernc.org/sqlite, a SQLite written in Go, so the hermes package and hermes/convert stay without one: hermes/convert takes OpenStore in its Options.

The database is never opened in place: Open reads a private copy of it and its write-ahead log, which internal/sqlite makes and checks against Hermes writing to it while it copies, as opencode/sqlite does OpenCode's. Hermes keeps state.db in WAL mode and writes to it from every process of a profile, the gateway's included.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("the database kept changing while it was copied; Hermes may be running, try again when it is idle")

ErrBusy is returned by Open when the database kept changing while it was copied: Hermes is writing to it.

View Source
var ErrNotHermes = errors.New("the database holds no sessions and messages tables of Hermes' (sessions with source and started_at, messages with session_id, role and timestamp)")

ErrNotHermes is returned by Open for a database without Hermes' sessions and messages tables.

Functions

func Fixture

func Fixture(path, script string) (io.Closer, error)

Fixture builds a database at path from SQL text, for tests: the fixtures of this module are SQL text, never database files.

func OpenStore

func OpenStore(path string) (hermes.Database, error)

OpenStore is Open as hermes/convert takes it, in its Options.OpenDatabase.

func Probe

func Probe(path string) bool

Probe reports whether the file at path is a Hermes database, reading its schema without copying it: the file is opened immutable, which takes no lock and writes nothing beside it, and reads what has been checkpointed into it. A database whose schema is still only in its write-ahead log, as one a running Hermes created may be, is read from a copy instead.

func RemoveCopies

func RemoveCopies()

RemoveCopies removes the copy of every database open, for a program interrupted while it reads one.

Types

type DB

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

DB is a copy of a Hermes database, open for reading. It implements hermes.Store. A DB is not safe for concurrent use.

func Open

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

Open copies the database at path and opens the copy. Close removes it.

func (*DB) Close

func (d *DB) Close() error

Close closes the copy and removes it.

func (*DB) Delegations

func (d *DB) Delegations() ([]*hermes.Delegation, error)

Delegations reads async_delegations.

func (*DB) Messages

func (d *DB) Messages(sessionID string) ([]*hermes.Message, error)

Messages reads a session's rows of messages in id order.

func (*DB) ModelUsage

func (d *DB) ModelUsage(sessionID string) ([]hermes.Columns, error)

ModelUsage reads a session's rows of session_model_usage.

func (*DB) Name

func (d *DB) Name() string

Name is the database's file name.

func (*DB) Orphans

func (d *DB) Orphans(map[string]bool) ([]*hermes.Stray, error)

Orphans lists the rows of messages whose session has no row in sessions, or a row that cannot be read. known is not read: every row of a session is read with it.

func (*DB) Sessions

func (d *DB) Sessions() ([]*hermes.Session, []*hermes.Stray, error)

Sessions lists the rows of sessions.

func (*DB) SystemPrompt

func (d *DB) SystemPrompt(hash string) (string, bool)

SystemPrompt reads a prompt of system_prompts.

func (*DB) Units

func (d *DB) Units() (int, error)

Units counts the rows a conversion accounts for, those of sessions and messages, so a test can hold a report's tally to it.

func (*DB) Version

func (d *DB) Version() (int, bool)

Version is the schema version schema_version records.

Jump to

Keyboard shortcuts

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