store

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package store persists sessions and their messages in one sqlite file, the ledger everything else replays from. Pure Go driver, so the binary stays CGO-free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	ID      int64
	Spec    string
	Prompt  string
	Channel string
	Chat    string
	Enabled bool
	LastRun time.Time
	Created time.Time
	Label   string
}

Job is one scheduled prompt. LastRun is zero until it has run once. Label is empty for user jobs; a non-empty label marks a job the daemon owns and keeps unique, like the heartbeat.

type Run

type Run struct {
	ID      int64
	JobID   int64
	Started time.Time
	OK      bool
	Output  string
}

Run is one recorded execution of a job.

type Session

type Session struct {
	ID       int64
	Name     string
	Channel  string
	Created  time.Time
	Updated  time.Time
	Messages int
}

Session is one conversation's row.

type Store

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

Store wraps the sqlite handle.

func Open

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

Open opens (creating if needed) the ledger at path.

func (*Store) AddJob

func (s *Store) AddJob(spec, prompt, channel, chat string) (int64, error)

AddJob inserts an enabled job and returns its id.

func (*Store) Append

func (s *Store) Append(sessionID int64, msgs []provider.Message) error

Append writes msgs to the session in order, after everything already there.

func (*Store) Bind

func (s *Store) Bind(channel, chat, session string) error

Bind points a channel's chat at a named session, so the same conversation is reachable from more than one channel. Re-binding replaces the old target.

func (*Store) BindingFor

func (s *Store) BindingFor(channel, chat string) (string, bool, error)

BindingFor returns the session a chat is bound to, if any.

func (*Store) Close

func (s *Store) Close() error

Close releases the handle.

func (*Store) EnabledJobs

func (s *Store) EnabledJobs() ([]Job, error)

EnabledJobs lists only the jobs the scheduler should consider.

func (*Store) EnsureJob

func (s *Store) EnsureJob(label, spec, prompt, channel, chat string) (int64, error)

EnsureJob upserts a labelled job the daemon owns, keyed on label. On first call it inserts and returns the new id; later it refreshes the spec, prompt, channel, and chat so config changes take effect without duplicating the job. It never resets last_run, so catch-up still works across restarts.

func (*Store) Jobs

func (s *Store) Jobs() ([]Job, error)

Jobs lists every job, oldest first.

func (*Store) MarkRun

func (s *Store) MarkRun(id int64, when time.Time) error

MarkRun records that a job ran at the given time, so the next due time is computed from here. Setting it to now collapses any missed ticks into one.

func (*Store) Messages

func (s *Store) Messages(sessionID int64) ([]provider.Message, error)

Messages replays a session's history in order.

func (*Store) RecordRun

func (s *Store) RecordRun(jobID int64, when time.Time, ok bool, output string) error

RecordRun appends a run to the history.

func (*Store) RemoveJob

func (s *Store) RemoveJob(id int64) (bool, error)

RemoveJob deletes a job and reports whether it existed.

func (*Store) Runs

func (s *Store) Runs(limit int) ([]Run, error)

Runs returns the most recent runs across all jobs, newest first.

func (*Store) Session

func (s *Store) Session(name, channel string) (*Session, error)

Session returns the session named name, creating it on first use.

func (*Store) Sessions

func (s *Store) Sessions() ([]Session, error)

Sessions lists every session, most recently updated first.

func (*Store) SetJobEnabled

func (s *Store) SetJobEnabled(id int64, enabled bool) error

SetJobEnabled toggles a job on or off.

Jump to

Keyboard shortcuts

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