rundb

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSchemaTooNew = errors.New("rundb: schema too new")

ErrSchemaTooNew reports that a database carries a migration newer than this binary understands.

Functions

This section is empty.

Types

type ArtifactSyncRow

type ArtifactSyncRow struct {
	Sequence     uint64
	RelativePath string
	ChangeKind   string
	Checksum     string
	SyncedAt     time.Time
}

ArtifactSyncRow is the persisted artifact sync history row.

type EventAuditStats

type EventAuditStats struct {
	EventCount             uint64
	MaxSequence            uint64
	SessionUpdateCount     uint64
	TranscriptMessageCount uint64
}

EventAuditStats summarizes persisted event/projection counts without loading event payloads.

type EventListResult

type EventListResult struct {
	Events  []events.Event
	HasMore bool
}

EventListResult captures one ordered event window from the canonical log.

type HookRunRecord

type HookRunRecord struct {
	ID          string
	HookName    string
	Source      string
	Outcome     string
	DurationNS  int64
	PayloadJSON string
	RecordedAt  time.Time
}

HookRunRecord captures one hook audit row persisted independently of the canonical event stream.

type JobStateRow

type JobStateRow struct {
	JobID       string
	TaskID      string
	Status      string
	AgentName   string
	SummaryJSON string
	UpdatedAt   time.Time
}

JobStateRow is the latest projected state for one job.

type RunDB

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

RunDB owns one per-run SQLite store.

func Open

func Open(ctx context.Context, path string) (*RunDB, error)

Open opens or creates one per-run operational store and applies migrations.

func (*RunDB) AppendSyntheticEvent

func (r *RunDB) AppendSyntheticEvent(
	ctx context.Context,
	kind events.EventKind,
	payload any,
) (events.Event, error)

AppendSyntheticEvent appends one synthetic canonical event with the next available sequence. It is intended for daemon-owned recovery flows that need to persist a terminal event after the original writer loop is gone.

func (*RunDB) Close

func (r *RunDB) Close() error

Close releases the underlying SQLite handle.

func (*RunDB) CloseContext

func (r *RunDB) CloseContext(ctx context.Context) error

CloseContext checkpoints the SQLite WAL and closes the underlying handle.

func (*RunDB) CurrentMaxSequence

func (r *RunDB) CurrentMaxSequence(ctx context.Context) (uint64, error)

CurrentMaxSequence returns the latest stored event sequence.

func (*RunDB) EventAuditStats

func (r *RunDB) EventAuditStats(ctx context.Context) (EventAuditStats, error)

EventAuditStats returns cheap integrity counters without event payload reads.

func (*RunDB) GetIntegrity

func (r *RunDB) GetIntegrity(ctx context.Context) (RunIntegrityState, error)

GetIntegrity returns the durable sticky integrity state for this run.

func (*RunDB) LastEvent

func (r *RunDB) LastEvent(ctx context.Context) (*events.Event, error)

LastEvent returns the latest persisted canonical event, if any.

func (*RunDB) ListArtifactSyncLog

func (r *RunDB) ListArtifactSyncLog(ctx context.Context) ([]ArtifactSyncRow, error)

ListArtifactSyncLog returns artifact sync rows in sequence order.

func (*RunDB) ListCompactedSessionUpdateEvents

func (r *RunDB) ListCompactedSessionUpdateEvents(ctx context.Context) ([]events.Event, error)

ListCompactedSessionUpdateEvents returns the session updates needed to rebuild a compact transcript: every non-tool update plus the first and latest update for each tool call.

func (*RunDB) ListEvents

func (r *RunDB) ListEvents(ctx context.Context, fromSeq uint64, limit int) (EventListResult, error)

ListEvents returns persisted events at or after fromSeq in sequence order. When limit is greater than zero, it returns at most limit+1 rows so callers can detect a following page without a second query.

func (*RunDB) ListEventsByKind

func (r *RunDB) ListEventsByKind(ctx context.Context, eventKinds []events.EventKind) ([]events.Event, error)

ListEventsByKind returns requested event kinds in sequence order.

func (*RunDB) ListHookRuns

func (r *RunDB) ListHookRuns(ctx context.Context) ([]HookRunRecord, error)

ListHookRuns returns persisted hook audit rows in recorded order.

func (*RunDB) ListJobState

func (r *RunDB) ListJobState(ctx context.Context) ([]JobStateRow, error)

ListJobState returns projected job rows ordered by job id.

func (*RunDB) ListTokenUsage

func (r *RunDB) ListTokenUsage(ctx context.Context) ([]TokenUsageRow, error)

ListTokenUsage returns token-usage rows ordered by timestamp.

func (*RunDB) ListTranscriptMessages

func (r *RunDB) ListTranscriptMessages(ctx context.Context) ([]TranscriptMessageRow, error)

ListTranscriptMessages returns projected transcript rows in sequence order.

func (*RunDB) ListTranscriptMessagesTail

func (r *RunDB) ListTranscriptMessagesTail(
	ctx context.Context,
	limit int,
	maxBytes int,
) ([]TranscriptMessageRow, error)

ListTranscriptMessagesTail returns a bounded transcript tail in sequence order.

func (*RunDB) Path

func (r *RunDB) Path() string

Path reports the on-disk database path.

func (*RunDB) RecordHookRun

func (r *RunDB) RecordHookRun(ctx context.Context, record HookRunRecord) error

RecordHookRun persists one hook audit row.

func (*RunDB) StoreEventBatch

func (r *RunDB) StoreEventBatch(ctx context.Context, items []events.Event) (retErr error)

StoreEventBatch persists canonical events and projection rows in one transaction.

func (*RunDB) UpsertIntegrity

func (r *RunDB) UpsertIntegrity(ctx context.Context, update RunIntegrityUpdate) (RunIntegrityState, error)

UpsertIntegrity merges the supplied integrity update into the sticky durable run-integrity row and returns the merged result.

type RunIntegrityState

type RunIntegrityState struct {
	Incomplete              bool
	Reasons                 []string
	JournalTerminalDrops    uint64
	JournalNonTerminalDrops uint64
	FirstDetectedAt         time.Time
	UpdatedAt               time.Time
}

RunIntegrityState is the durable sticky integrity state for one run.

type RunIntegrityUpdate

type RunIntegrityUpdate struct {
	Incomplete              bool
	Reasons                 []string
	JournalTerminalDrops    uint64
	JournalNonTerminalDrops uint64
}

RunIntegrityUpdate captures one integrity-state update that should merge with any existing sticky run-integrity row.

type SchemaTooNewError

type SchemaTooNewError struct {
	CurrentVersion int
	KnownVersion   int
}

SchemaTooNewError carries the current database and binary migration versions.

func (SchemaTooNewError) Error

func (e SchemaTooNewError) Error() string

func (SchemaTooNewError) Is

func (e SchemaTooNewError) Is(target error) bool

type TokenUsageRow

type TokenUsageRow struct {
	TurnID       string
	InputTokens  int
	OutputTokens int
	TotalTokens  int
	CostAmount   *float64
	Timestamp    time.Time
}

TokenUsageRow is the persisted token usage projection for one turn or aggregate record.

type TranscriptMessageRow

type TranscriptMessageRow struct {
	Sequence     uint64
	Stream       string
	Role         string
	Content      string
	MetadataJSON string
	Timestamp    time.Time
}

TranscriptMessageRow is the projected transcript row for one event sequence.

func ProjectTranscriptMessage

func ProjectTranscriptMessage(item events.Event) (TranscriptMessageRow, bool, error)

ProjectTranscriptMessage projects one canonical event into the persisted transcript read model used for cold snapshots and replay.

Jump to

Keyboard shortcuts

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