reflect

package
v0.68.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Overview

Package reflect is Stella's self-improvement loop: it reviews finished conversations on a scheduler builtin, gates candidates, reconciles the skills it owns, and curates skill usage. Everything it writes is attributed to reflect so a human can tell it apart from an authored change.

Index

Constants

View Source
const BuiltinJobName = "reflect-review"

BuiltinJobName is the scheduler builtin name reflect registers under. Exported so gateway wiring and operational tooling refer to one source.

Variables

This section is empty.

Functions

func NewBuiltinHandler added in v0.38.0

func NewBuiltinHandler(cfg Config) (scheduler.OnJobFunc, error)

NewBuiltinHandler returns a scheduler.OnJobFunc that runs one reflect review cycle per fire. Cycle-level failures (store errors, ctx cancellation) surface as errors so the scheduler marks the run errored. Per-agent failures are still logged inside the service and do not fail the run.

Types

type CandidateGateConfig added in v0.60.0

type CandidateGateConfig struct {
	Weights        map[string]float64
	CoreFields     []string
	CoreFloor      int
	Threshold      float64
	Cap            int
	TieBreakFields []string
}

type CandidateGateDecision added in v0.60.0

type CandidateGateDecision struct {
	Ref               CandidateRef
	NormalizedOverall float64
	Scores            map[string]int
	Reason            RejectReason
}

type CandidateGateInput added in v0.60.0

type CandidateGateInput struct {
	Ref     CandidateRef
	Content string
	Scores  map[string]int
}

type CandidateGateResult added in v0.60.0

type CandidateGateResult struct {
	Accepted []CandidateGateDecision
	Rejected []CandidateGateDecision
}

type CandidateGateSettings added in v0.60.0

type CandidateGateSettings struct {
	FactWeights       map[string]float64
	FactThreshold     float64
	FactSubjectCap    int
	SkillWeights      map[string]float64
	SkillThreshold    float64
	SkillCandidateCap int
}

CandidateGateSettings keeps #532 score gates configurable without exposing a persistent confidence field or coupling thresholds to prompt text.

type CandidateRef added in v0.60.0

type CandidateRef string

CandidateRef is a stable in-review identifier assigned after generation. It is intentionally sequential in #532; hash-based refs are deferred.

type Config

type Config struct {
	StateStore pkgplugins.StateStore
	Memory     memory.Provider
	Store      Store
	// Snapshots loads credential-aware per-agent snapshots for review.
	Snapshots  config.SnapshotLoader
	SkillStore reflectSkillStore
	// SkillAuthorizer applies Skill domain rules to Reflect's staged writes.
	SkillAuthorizer   skillWriteAuthorizer
	UsageCuratorStore UsageCuratorStore
	Log               *slog.Logger
	Providers         func(api, apiKey, baseURL string) (providers.StreamFunc, error)
	CandidateGates    CandidateGateSettings
	// UsageCuratorSettings defaults to armed. Operators may switch to shadow to
	// stop lifecycle writes while keeping scans and telemetry active.
	UsageCuratorSettings UsageCuratorSettings
	// Services provides the per-agent session registry used for review target
	// listing and owner-scoped memory coordinates.
	Services agent.ServiceManager
}

Config holds dependencies for the reflect service.

type RejectReason added in v0.60.0

type RejectReason string

type ReviewSkip added in v0.60.0

type ReviewSkip struct {
	Reason ReviewSkipReason
	Role   string
	At     time.Time
	// Seq fields identify the skipped review boundary when the history source
	// can provide stable ordering. They stay zero for timestamp-only fallback.
	FirstSeq int64
	LastSeq  int64
	Size     int
}

type ReviewSkipReason added in v0.60.0

type ReviewSkipReason string

type ReviewUnit added in v0.60.0

type ReviewUnit struct {
	Text            string
	ReviewFromAt    time.Time
	ReviewFromSeq   int64
	LastIncludedAt  time.Time
	LastIncludedSeq int64
	// Truncated means more fresh content exists after LastIncluded*, but it did
	// not fit in this bounded window and must be picked up by a later cycle.
	Truncated       bool
	Skipped         []ReviewSkip
	FreshCount      int
	PrivateOneToOne bool
	SkillUsage      []reviewSkillUsage
}

ReviewUnit is the bounded, fresh conversation window consumed by candidate generators. It keeps the watermark boundary explicit so each reflect line can advance independently after a successful review.

type Service

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

Service runs background conversation review.

func New

func New(cfg Config) *Service

New creates a new reflect service.

func (*Service) ReviewConversationReconciledCandidates added in v0.60.0

func (s *Service) ReviewConversationReconciledCandidates(ctx context.Context, snap *config.Snapshot, target reviewTarget) (candidatePipelineResult, error)

ReviewConversationReconciledCandidates runs structured candidate generation, evaluation, reconciliation, and writes. A line advances only after all work for that line completes.

func (*Service) RunOnce

func (s *Service) RunOnce(ctx context.Context) error

RunOnce executes the scheduler-owned review cycle across all enabled agents. Production and immediate operator runs must go through the registered scheduler builtin (using scheduler.RunJobNow for the latter) so concurrency control and run records are preserved. It returns the first cycle-level error; per-agent failures are logged inside runCycle and do not surface here.

type Store added in v0.38.0

type Store interface {
	ListEnabledAgents(ctx context.Context) ([]config.Agent, error)
}

Store lists the Agents Reflect reviews. Snapshot loading is a separate, credential-aware dependency.

type UsageCuratorMode added in v0.60.0

type UsageCuratorMode string
const (
	UsageCuratorModeShadow UsageCuratorMode = "shadow"
	UsageCuratorModeArmed  UsageCuratorMode = "armed"
)

type UsageCuratorSettings added in v0.60.0

type UsageCuratorSettings struct {
	Mode               UsageCuratorMode
	KnowledgeMaxIdle   time.Duration
	SkillMaxIdle       time.Duration
	SkillLowUseIdle    time.Duration
	SkillLowUseMaxUses int64
	RunInterval        time.Duration
	Now                func() time.Time
}

type UsageCuratorStore added in v0.60.0

type UsageCuratorStore interface {
	ListReflectUsagePairs(ctx context.Context) ([]usageCuratorPair, error)
	ListStaleReflectKnowledge(ctx context.Context, q usageCuratorKnowledgeQuery) ([]usageCuratorKnowledgeCandidate, error)
	ListStaleReflectSkills(ctx context.Context, q usageCuratorSkillQuery) ([]usageCuratorSkillCandidate, error)
}

func NewSQLUsageCuratorStore added in v0.60.0

func NewSQLUsageCuratorStore(q *sqlc.Queries) UsageCuratorStore

func NewSQLUsageCuratorStoreForPool added in v0.60.0

func NewSQLUsageCuratorStoreForPool(pool *pgxpool.Pool) UsageCuratorStore

NewSQLUsageCuratorStoreForPool builds a UsageCuratorStore backed by the given connection pool, owning construction of its sqlc query set.

Jump to

Keyboard shortcuts

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