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
- type Job
- type Plan
- type Run
- type Session
- type Step
- type Store
- func (s *Store) AddJob(spec, prompt, channel, chat string) (int64, error)
- func (s *Store) AddSpent(id string, tokens int) (int, error)
- func (s *Store) AddStep(st *Step) (int64, error)
- func (s *Store) Append(sessionID int64, msgs []provider.Message) error
- func (s *Store) Bind(channel, chat, session string) error
- func (s *Store) BindingFor(channel, chat string) (string, bool, error)
- func (s *Store) Close() error
- func (s *Store) CreatePlan(p *Plan) (string, error)
- func (s *Store) EnabledJobs() ([]Job, error)
- func (s *Store) EnsureJob(label, spec, prompt, channel, chat string) (int64, error)
- func (s *Store) Jobs() ([]Job, error)
- func (s *Store) MarkRun(id int64, when time.Time) error
- func (s *Store) MarkStep(rowID int64, status, result string, tokens int, startedMS, endedMS int64) error
- func (s *Store) Messages(sessionID int64) ([]provider.Message, error)
- func (s *Store) NewAttempt(from Step) (int64, error)
- func (s *Store) Plan(id string) (*Plan, error)
- func (s *Store) Plans(status string) ([]Plan, error)
- func (s *Store) RecordRun(jobID int64, when time.Time, ok bool, output string) error
- func (s *Store) RemoveJob(id int64) (bool, error)
- func (s *Store) Runs(limit int) ([]Run, error)
- func (s *Store) Session(name, channel string) (*Session, error)
- func (s *Store) Sessions() ([]Session, error)
- func (s *Store) SetJobEnabled(id int64, enabled bool) error
- func (s *Store) SetPlanStatus(id, status string) error
- func (s *Store) StepHistory(planID string) ([]Step, error)
- func (s *Store) Steps(planID string) ([]Step, error)
Constants ¶
const ( PlanPlanning = "planning" PlanRunning = "running" PlanPaused = "paused" PlanDone = "done" PlanFailed = "failed" PlanCancelled = "cancelled" )
Plan statuses. A plan is terminal once done, failed, or cancelled.
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 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 (*Store) AddSpent ¶ added in v0.2.3
AddSpent adds to a plan's running token total and returns the new total.
func (*Store) AddStep ¶ added in v0.2.3
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) Bind ¶
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 ¶
BindingFor returns the session a chat is bound to, if any.
func (*Store) CreatePlan ¶ added in v0.2.3
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 ¶
EnabledJobs lists only the jobs the scheduler should consider.
func (*Store) EnsureJob ¶
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) MarkRun ¶
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) NewAttempt ¶ added in v0.2.3
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) Plans ¶ added in v0.2.3
Plans lists plans, newest first, optionally filtered to a status.
func (*Store) SetJobEnabled ¶
SetJobEnabled toggles a job on or off.
func (*Store) SetPlanStatus ¶ added in v0.2.3
SetPlanStatus flips a plan's status and touches updated_at.
func (*Store) StepHistory ¶ added in v0.2.3
StepHistory returns every attempt row for a plan, oldest first, the full append-only journal an audit or a `tomo plan` view reads.