reflect

package
v0.60.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

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.

View Source
const (
	// RecentlyForgottenKindKnowledge identifies Reflect-owned world facts that
	// the usage curator deprecated.
	RecentlyForgottenKindKnowledge = "knowledge"
)

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
	SkillStore pkgplugins.SkillStore
	// SkillAuthorizer applies Skill domain rules to reflect's staged writes (the
	// reconciliation-plan/usage-curator path); when nil those fail closed.
	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 per-agent session registries for review target listing.
	// When set, reflect uses Registry.ListForReview and Registry.MemoryScope
	// instead of calling memory.SessionManager directly.
	Services agent.ServiceManager
}

Config holds dependencies for the reflect service.

type RecentlyForgottenItems added in v0.60.0

type RecentlyForgottenItems struct {
	Knowledge []RecentlyForgottenKnowledgeItem
}

RecentlyForgottenItems contains the restorable curator-deprecated records.

type RecentlyForgottenKnowledgeItem added in v0.60.0

type RecentlyForgottenKnowledgeItem struct {
	Kind                        string
	FactID                      string
	Content                     string
	DeprecatedAt                time.Time
	CuratorRule                 string
	LastUsedAt                  string
	MemoryVersionAfterDeprecate int64
	DeprecatedChangelogID       string
}

RecentlyForgottenKnowledgeItem includes fact content so an admin can inspect exactly what would be restored.

type RecentlyForgottenQuery added in v0.60.0

type RecentlyForgottenQuery struct {
	UserID  string
	AgentID string
	Kind    string
	Limit   int32
}

RecentlyForgottenQuery scopes the internal/admin listing to one user-agent pair. Empty Kind returns Knowledge.

type RejectReason added in v0.60.0

type RejectReason string

type RestoreForgottenRequest added in v0.60.0

type RestoreForgottenRequest struct {
	Kind       string
	ID         string
	UserID     string
	AgentID    string
	RestoredBy string
	Reason     string
}

RestoreForgottenRequest identifies one curator-deprecated record to restore.

type RestoreForgottenResult added in v0.60.0

type RestoreForgottenResult struct {
	Kind      string
	Restored  bool
	Knowledge *memory.Fact
}

RestoreForgottenResult returns the restored Knowledge item.

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
	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 SQLForgottenRestoreService added in v0.60.0

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

SQLForgottenRestoreService provides the internal/admin restore path for items returned by SQLRecentlyForgottenStore.

func NewSQLForgottenRestoreService added in v0.60.0

func NewSQLForgottenRestoreService(db *pgxpool.Pool, q *sqlc.Queries) SQLForgottenRestoreService

func (SQLForgottenRestoreService) RestoreForgotten added in v0.60.0

RestoreForgotten is the internal/admin restore entrypoint for curator-deprecated Reflect-owned knowledge. It does not expose a user-facing API by itself; callers still decide authentication and authorization.

type SQLRecentlyForgottenStore added in v0.60.0

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

SQLRecentlyForgottenStore lists curator-deprecated Reflect records that are eligible for internal/admin restore.

func NewSQLRecentlyForgottenStore added in v0.60.0

func NewSQLRecentlyForgottenStore(q *sqlc.Queries) SQLRecentlyForgottenStore

func (SQLRecentlyForgottenStore) ListRecentlyForgotten added in v0.60.0

ListRecentlyForgotten returns only records whose latest deprecate changelog was written by the usage curator.

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)
	Snapshot(ctx context.Context, agentID string) (*config.Snapshot, error)
}

Store is the read-only subset of config.Store reflect needs to run a review cycle. Narrowed from config.Store so dispatcher tests can supply a fake without implementing the full config surface; satisfied by config.Store via structural typing.

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