store

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 9 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

View Source
const (
	PlanPlanning  = "planning"
	PlanRunning   = "running"
	PlanPaused    = "paused"
	PlanDone      = "done"
	PlanFailed    = "failed"
	PlanCancelled = "cancelled"
)

Plan statuses. A plan is terminal once done, failed, or cancelled.

View Source
const (
	StepPending = "pending"
	StepReady   = "ready"
	StepRunning = "running"
	StepDone    = "done"
	StepFailed  = "failed"
	StepSkipped = "skipped"
)

Step statuses, the lifecycle the orchestrator advances a step through. A step is terminal once done, failed, or skipped, and a terminal row is never rewritten: a retry is a fresh attempt row (see NewAttempt).

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 Plan added in v0.2.3

type Plan struct {
	ID           string
	Session      string
	Channel      string
	Goal         string
	Status       string
	BudgetTokens int
	BudgetSteps  int
	BudgetWallMS int64
	SpentTokens  int
	Attended     bool
	Created      time.Time
	Updated      time.Time
}

Plan is one job: a goal, a budget, and a status, owning a set of steps. It is the plan-as-artifact from spec 2080/ostres, written before anything runs.

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 Step added in v0.2.3

type Step struct {
	RowID     int64
	PlanID    string
	Idx       int
	Attempt   int
	UID       string
	Goal      string
	Deps      []int
	Inputs    map[string]string
	Executor  string
	PostJSON  string // the postcondition, opaque JSON the orch layer interprets
	Status    string
	Result    string
	Tokens    int
	StartedMS int64
	EndedMS   int64
}

Step is one node of a plan's DAG. Deps and the #E<idx> placeholders in Inputs are indexes into the same plan, so the orchestrator schedules on Deps and resolves Inputs from earlier steps' results at dispatch time. A step may have several attempt rows; the ones the orchestrator drives are the latest per idx.

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) AddSpent added in v0.2.3

func (s *Store) AddSpent(id string, tokens int) (int, error)

AddSpent adds to a plan's running token total and returns the new total.

func (*Store) AddStep added in v0.2.3

func (s *Store) AddStep(st *Step) (int64, error)

AddStep appends a step to a plan as its first attempt. It fills the UID if empty and returns the new row 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) CreatePlan added in v0.2.3

func (s *Store) CreatePlan(p *Plan) (string, error)

CreatePlan inserts a plan. An empty ID is filled with a fresh random id, which is returned so the caller can address the new plan.

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) MarkStep added in v0.2.3

func (s *Store) MarkStep(rowID int64, status, result string, tokens int, startedMS, endedMS int64) error

MarkStep advances a step row's status, and when terminal records its result, tokens, and timestamps. It refuses to rewrite a row that is already terminal, which is the append-only discipline: a retry must be a NewAttempt, not an overwrite of a done or failed row.

func (*Store) Messages

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

Messages replays a session's history in order.

func (*Store) NewAttempt added in v0.2.3

func (s *Store) NewAttempt(from Step) (int64, error)

NewAttempt clones a step's definition into a fresh pending row with the next attempt number, leaving the failed attempt in place. This is how repair works without destroying the history that makes replay and audit honest.

func (*Store) Plan added in v0.2.3

func (s *Store) Plan(id string) (*Plan, error)

Plan reads one plan by id.

func (*Store) Plans added in v0.2.3

func (s *Store) Plans(status string) ([]Plan, error)

Plans lists plans, newest first, optionally filtered to a status.

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.

func (*Store) SetPlanStatus added in v0.2.3

func (s *Store) SetPlanStatus(id, status string) error

SetPlanStatus flips a plan's status and touches updated_at.

func (*Store) StepHistory added in v0.2.3

func (s *Store) StepHistory(planID string) ([]Step, error)

StepHistory returns every attempt row for a plan, oldest first, the full append-only journal an audit or a `tomo plan` view reads.

func (*Store) Steps added in v0.2.3

func (s *Store) Steps(planID string) ([]Step, error)

Steps returns the latest attempt of every step in a plan, ordered by idx, the live view the orchestrator schedules over.

Jump to

Keyboard shortcuts

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