preferences

package
v0.0.0-...-2769864 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package preferences validates and resolves per-user agent preferences: the class-authored schema (AgentClass.spec.userPreferences), the platform admin's globals (AgentSettings.spec.classUserPreferences), and the user's saved values (the user_preference memory kind). Pure — no I/O.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateSchema

func ValidateSchema(schema []v1alpha1.UserPreferenceSchema) error

ValidateSchema checks a class's userPreferences list for self-consistency.

func ValidateValue

func ValidateValue(sch v1alpha1.UserPreferenceSchema, v apiextv1.JSON) error

ValidateValue checks one value against one preference's declared shape. A JSON null is valid for every type: it is the "cleared" tombstone.

Types

type CommitRequest

type CommitRequest struct {
	Key     string         `json:"key"`
	Value   *apiextv1.JSON `json:"value,omitempty"`
	Subject string         `json:"subject"`
}

CommitRequest is the HTTP wire type for updating a user preference. Value nil (or JSON null) clears the user layer for Key. Subject is the verified decider's canonical user id (bare, no "user:").

type Resolved

type Resolved struct {
	Name        string                         `json:"name"`
	Type        string                         `json:"type"`
	Description string                         `json:"description,omitempty"`
	Enum        []v1alpha1.PreferenceEnumValue `json:"enum,omitempty"`
	Pattern     string                         `json:"pattern,omitempty"`
	Value       *apiextv1.JSON                 `json:"value,omitempty"` // nil when unset
	Source      Source                         `json:"source"`
	Locked      bool                           `json:"locked"`
	Note        string                         `json:"note,omitempty"` // violation affecting this key
	// Visibility is always "self" or "class" — never empty. Any schema value
	// other than an explicit "class" (unset included) normalizes to "self"
	// here, so every consumer compares against a concrete value and an
	// invalid schema value can never widen who reads a preference.
	Visibility string `json:"visibility"`
}

type Snapshot

type Snapshot struct {
	Keys       []Resolved `json:"keys"`
	Violations []string   `json:"violations,omitempty"`
}

func Resolve

func Resolve(schema []v1alpha1.UserPreferenceSchema,
	globals map[string]v1alpha1.PreferenceGlobal,
	user map[string]apiextv1.JSON) Snapshot

Resolve computes the precedence-ordered effective value for each key in the schema. Precedence per key: locked global → user value → global → class default → unset. Every candidate is re-validated against the current schema. A null user value is the cleared tombstone and is skipped as if absent. Violations are loud: malformed globals are ignored with a Note, schema-invalidated user values are treated absent with a Note.

type SnapshotResponse

type SnapshotResponse struct {
	Subject        string   `json:"subject,omitempty"`
	ClassNamespace string   `json:"classNamespace"`
	ClassName      string   `json:"className"`
	Snapshot       Snapshot `json:"snapshot"`
	// Note carries a subject-resolution Reason for a ?user-ref= read that did
	// not resolve (unknown reference form, no linked platform user, subject
	// resolution unavailable on this cluster, …) — empty on a turn-derived
	// read and on a resolved user-ref read. The agent relays it verbatim; it
	// is bounded the same way subjectresolve.Resolution.Reason already is.
	Note string `json:"note,omitempty"`
}

SnapshotResponse is the HTTP wire type for user preferences snapshots. Subject is the canonical user id the user layer resolved for; empty when the turn had no human author (service/webhook/cron sessions).

type Source

type Source string
const (
	SourceUnset   Source = "unset"
	SourceDefault Source = "default"
	SourceGlobal  Source = "global"
	SourceUser    Source = "user"
	SourceLocked  Source = "locked"
)

Jump to

Keyboard shortcuts

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