reflection

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package reflection implements the Reflection domain: persisted AI-generated reflection records for daily reviews, weekly summaries, and entity-specific analysis (task, decision, proposal, knowledge, system).

Index

Constants

This section is empty.

Variables

View Source
var AllowedTypes = map[string]bool{
	"daily":     true,
	"weekly":    true,
	"task":      true,
	"decision":  true,
	"proposal":  true,
	"knowledge": true,
	"system":    true,
}

AllowedTypes is the set of valid reflection type values.

View Source
var ErrNotFound = errors.New("reflection: not found")

ErrNotFound is returned when a requested reflection does not exist.

Functions

This section is empty.

Types

type CreateParams

type CreateParams struct {
	WorkspaceID       *uuid.UUID
	Type              string
	RelatedEntityType *string
	RelatedEntityID   *uuid.UUID
	Summary           string
	Insights          json.RawMessage
	PatternsDetected  json.RawMessage
	SuggestedActions  json.RawMessage
	Confidence        float64
}

CreateParams holds the fields required to record a new reflection.

type ListParams

type ListParams struct {
	WorkspaceID *uuid.UUID
	Type        *string
	Limit       int // 0 = default 20
}

ListParams narrows a List call.

type Reflection

type Reflection struct {
	ID                uuid.UUID       `json:"id"`
	WorkspaceID       *uuid.UUID      `json:"workspace_id,omitempty"`
	Type              string          `json:"type"`
	RelatedEntityType *string         `json:"related_entity_type,omitempty"`
	RelatedEntityID   *uuid.UUID      `json:"related_entity_id,omitempty"`
	Summary           string          `json:"summary"`
	Insights          json.RawMessage `json:"insights,omitempty"`
	PatternsDetected  json.RawMessage `json:"patterns_detected,omitempty"`
	SuggestedActions  json.RawMessage `json:"suggested_actions,omitempty"`
	Confidence        float64         `json:"confidence"`
	CreatedAt         time.Time       `json:"created_at"`
}

Reflection is the domain model for a persisted AI reflection record.

type Store

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

Store is the Postgres-backed implementation of StoreIface. It uses raw pgx without sqlc so the reflections table stays independent of the sqlc-generated query layer.

func New

func New(pool *pgxpool.Pool, workspaceID *uuid.UUID) *Store

New returns a Store backed by pool, scoped to the optional workspaceID. nil workspaceID = legacy unscoped mode.

func (*Store) ByRelatedEntity

func (s *Store) ByRelatedEntity(
	ctx context.Context, workspaceID *uuid.UUID, entityType string, entityID uuid.UUID, limit int,
) ([]*Reflection, error)

ByRelatedEntity returns reflections scoped to a specific related entity, ordered by created_at DESC, capped at limit rows.

func (*Store) Create

func (s *Store) Create(ctx context.Context, p CreateParams) (*Reflection, error)

Create inserts a new reflection and returns the persisted record.

func (*Store) GetLatest

func (s *Store) GetLatest(ctx context.Context, workspaceID *uuid.UUID, reflType string) (*Reflection, error)

GetLatest returns the most recent reflection of a given type in the workspace. Returns ErrNotFound when no matching reflection exists.

func (*Store) List

func (s *Store) List(ctx context.Context, p ListParams) ([]*Reflection, error)

List returns reflections matching the filter, ordered by created_at DESC.

func (*Store) PruneOlderThan

func (s *Store) PruneOlderThan(ctx context.Context, cutoff time.Time) (int64, error)

PruneOlderThan hard-deletes reflection rows with created_at < cutoff. Called daily by the scheduler to enforce the 180-day TTL per backend-security-design.md §1.3.

func (*Store) RecentWithPatterns

func (s *Store) RecentWithPatterns(ctx context.Context, workspaceID *uuid.UUID, since time.Time, limit int) ([]*Reflection, error)

RecentWithPatterns returns reflections that have a non-NULL patterns_detected column and were created on or after since, ordered by created_at DESC.

type StoreIface

type StoreIface interface {
	Create(ctx context.Context, p CreateParams) (*Reflection, error)
	List(ctx context.Context, p ListParams) ([]*Reflection, error)
	GetLatest(ctx context.Context, workspaceID *uuid.UUID, reflType string) (*Reflection, error)
	ByRelatedEntity(ctx context.Context, workspaceID *uuid.UUID, entityType string, entityID uuid.UUID, limit int) ([]*Reflection, error)
	RecentWithPatterns(ctx context.Context, workspaceID *uuid.UUID, since time.Time, limit int) ([]*Reflection, error)
	// PruneOlderThan hard-deletes reflection rows with created_at < cutoff.
	// Called daily by the scheduler to enforce the 180-day TTL per
	// backend-security-design.md §1.3.
	PruneOlderThan(ctx context.Context, cutoff time.Time) (int64, error)
}

StoreIface is the backend-agnostic contract for the Reflection domain.

Jump to

Keyboard shortcuts

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