store

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package store persists RuntimePulse state in a single SQLite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IngestResult

type IngestResult struct {
	Event         core.Event          `json:"event"`
	Continuations []core.Continuation `json:"continuations"`
}

IngestResult reports what one event produced.

type RetentionPolicy added in v1.2.0

type RetentionPolicy struct {
	SessionIdle     time.Duration
	ContinuationAge time.Duration
	EventAge        time.Duration
}

RetentionPolicy bounds how long pruned state lives. Windows are fixed constants in the daemon (owner decision: no flags, YAGNI).

type Store

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

func Open

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

func (*Store) AddRule

func (s *Store) AddRule(r core.Rule) (core.Rule, error)

AddRule stores a rule, assigning id and created_at.

func (*Store) AddWatch

func (s *Store) AddWatch(w watch.Watch) (watch.Watch, error)

AddWatch persists a watch; an existing watch with the same (type, target) is returned unchanged (idempotent create, spec §7.2).

func (*Store) ClaimContinuation

func (s *Store) ClaimContinuation(id string) (bool, error)

ClaimContinuation atomically moves a continuation pending → running. Returns false if it was not pending (already claimed or finished) — the DB row is the single source of truth for claims.

func (*Store) Close

func (s *Store) Close() error

func (*Store) GetSession

func (s *Store) GetSession(id string) (core.Session, bool, error)

func (*Store) Ingest

func (s *Store) Ingest(ev core.Event) (IngestResult, error)

Ingest is the outbox transaction (spec §5): store the event, match active rules, render prompts, create pending continuations, and consume oneShot rules — atomically. (rule_id, event_id) uniqueness makes re-delivery of the same event a no-op.

Everything runs on the tx: with SetMaxOpenConns(1), touching s.db while the tx is open would deadlock the connection pool.

func (*Store) InsertEvent

func (s *Store) InsertEvent(ev core.Event) error

InsertEvent stores an event; re-inserting the same id is a no-op.

func (*Store) InsertManualContinuation

func (s *Store) InsertManualContinuation(sessionID, prompt string) (core.Continuation, error)

InsertManualContinuation creates a rule-less pending continuation (the CLI `continue` command / continuation.run RPC).

func (*Store) ListContinuations

func (s *Store) ListContinuations(state string) ([]core.Continuation, error)

ListContinuations returns continuations, optionally filtered by state.

func (*Store) ListEvents

func (s *Store) ListEvents(evType string, limit int) ([]core.Event, error)

ListEvents returns newest-first events, optionally filtered by type.

func (*Store) ListRules

func (s *Store) ListRules(includeInactive bool) ([]core.Rule, error)

ListRules returns rules; includeInactive=false filters out consumed and expired.

func (*Store) ListSessions

func (s *Store) ListSessions() ([]core.Session, error)

func (*Store) ListWatches

func (s *Store) ListWatches() ([]watch.Watch, error)

func (*Store) NextPendingForSession

func (s *Store) NextPendingForSession(sessionID string) (core.Continuation, bool, error)

NextPendingForSession returns the oldest pending continuation for a session (FIFO order: created_at, then id).

func (*Store) PendingSessions

func (s *Store) PendingSessions() ([]string, error)

PendingSessions returns the distinct session ids that have pending work.

func (*Store) PruneEvents

func (s *Store) PruneEvents(before time.Time) (int64, error)

PruneEvents deletes events older than the cutoff, returning the count.

func (*Store) RegisterSession

func (s *Store) RegisterSession(sess core.Session) (core.Session, error)

RegisterSession upserts a session; new sessions start as waiting. Re-registering preserves existing state and created_at; the returned session is re-read from the database so it never disagrees with it.

func (*Store) RemoveRule

func (s *Store) RemoveRule(id string) error

func (*Store) RemoveWatch

func (s *Store) RemoveWatch(id string) error

func (*Store) ResetRunningContinuations

func (s *Store) ResetRunningContinuations() (int64, error)

ResetRunningContinuations moves orphaned running rows back to pending (daemon crashed mid-run). At-least-once: a continuation whose result was lost may run twice; that beats a lost wake-up.

func (*Store) SetSessionState

func (s *Store) SetSessionState(id string, st core.SessionState) error

func (*Store) Sweep added in v1.2.0

func (s *Store) Sweep(now time.Time, p RetentionPolicy) (SweepResult, error)

Sweep garbage-collects expired state in ONE transaction:

  • sessions idle past SessionIdle — but never one that is running or referenced by an active (unconsumed, unexpired) rule: an armed session must survive until its rule fires or expires;
  • terminal (completed/failed) continuations older than ContinuationAge — pending/running are never touched;
  • events older than EventAge.

The three prunes are independent by design: deleting a session does not cascade into its historical continuations (those age out on their own and are inert once terminal).

func (*Store) UpdateContinuationResult

func (s *Store) UpdateContinuationResult(id string, state core.ContinuationState,
	command string, exitCode *int, outputSummary string) error

UpdateContinuationResult records a finished run.

type SweepResult added in v1.2.0

type SweepResult struct {
	Sessions      int64
	Continuations int64
	Events        int64
}

SweepResult reports what one retention sweep removed.

Jump to

Keyboard shortcuts

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