Documentation
¶
Overview ¶
Package patterns owns the durable motion pattern and program library, authoring transforms, import/export, and visible preference feedback.
Index ¶
- Constants
- Variables
- func AuditionDefinition(definition motion.PatternDefinition, feel string) motion.PatternDefinition
- type CurationChoice
- type Feedback
- type ImportResult
- type Library
- func (l *Library) ApplyFeedback(patternID string, rating int) (Feedback, Pattern, error)
- func (l *Library) ApplyFeedbackContext(ctx context.Context, patternID string, rating int) (Feedback, Pattern, error)
- func (l *Library) AutoDisable() (bool, error)
- func (l *Library) Close() error
- func (l *Library) CreatePattern(input PatternInput) (Pattern, error)
- func (l *Library) CreateProgram(name, origin string, points []motion.CurvePoint, duration int64) (Program, error)
- func (l *Library) DeletePattern(id string) error
- func (l *Library) DeleteProgram(id string) error
- func (l *Library) EnabledChoices() ([]CurationChoice, error)
- func (l *Library) ExportPattern(id string) ([]byte, string, error)
- func (l *Library) ExportProgram(id string) ([]byte, string, error)
- func (l *Library) FeedbackHistory(limit int) ([]Feedback, error)
- func (l *Library) Import(filename string, data []byte, asKind string) (ImportResult, error)
- func (l *Library) ListPatterns() ([]Pattern, error)
- func (l *Library) ListPrograms() ([]Program, error)
- func (l *Library) Pattern(id string) (Pattern, error)
- func (l *Library) Program(id string) (Program, error)
- func (l *Library) ResolveEnabled(id string) (motion.PatternDefinition, bool, error)
- func (l *Library) SetAutoDisable(enabled bool) error
- func (l *Library) Snapshot() (Snapshot, error)
- func (l *Library) Summary() (Summary, error)
- func (l *Library) UndoFeedback(id int64) (Feedback, Pattern, error)
- func (l *Library) UndoFeedbackContext(ctx context.Context, id int64) (Feedback, Pattern, error)
- func (l *Library) UpdatePattern(id string, patch PatternPatch) (Pattern, error)
- type Pattern
- type PatternInput
- type PatternPatch
- type PreviewResult
- type Program
- type Snapshot
- type Summary
Constants ¶
const ( // OriginBuiltin identifies code-generated catalog content. OriginBuiltin = "builtin" // OriginUser identifies directly authored content. OriginUser = "user" // OriginGenerated identifies app-generated user content. OriginGenerated = "generated" // OriginImported identifies finite content imported from a file. OriginImported = "imported" // PatternFileSchema is the share-file schema for one loop pattern. PatternFileSchema = "magichandy.pattern.v1" // ProgramFileSchema is the share-file schema for one finite program. ProgramFileSchema = "magichandy.program.v1" // MaxImportBytes bounds pattern/program upload bodies at the HTTP edge. MaxImportBytes = 8 << 20 )
Variables ¶
var ( // ErrPatternNotFound reports an unknown pattern identifier. ErrPatternNotFound = errors.New("pattern not found") // ErrProgramNotFound reports an unknown program identifier. ErrProgramNotFound = errors.New("program not found") // ErrBuiltinPattern protects built-in content from edit/delete operations. ErrBuiltinPattern = errors.New("built-in pattern content is read-only") // ErrFeedbackOrder prevents undo from overwriting a newer preference edit. ErrFeedbackOrder = errors.New("only the latest feedback for a pattern can be undone") // ErrInvalidContent identifies user-authored or imported content that cannot // be normalized safely. ErrInvalidContent = errors.New("invalid pattern library content") // ErrLibraryLimit reports a configured pattern or program capacity limit. ErrLibraryLimit = errors.New("pattern library capacity reached") // ErrFeedbackNotFound reports an unknown feedback identifier. ErrFeedbackNotFound = errors.New("feedback entry not found") // ErrFeedbackReverted reports a second undo attempt. ErrFeedbackReverted = errors.New("feedback entry is already reverted") )
Functions ¶
func AuditionDefinition ¶
func AuditionDefinition(definition motion.PatternDefinition, feel string) motion.PatternDefinition
AuditionDefinition applies a temporary backend-owned feel filter. It never mutates the saved pattern and still uses the shared PCHIP sampler.
Types ¶
type CurationChoice ¶
type CurationChoice struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags"`
Weight float64 `json:"weight"`
}
CurationChoice is prompt-safe enabled pattern metadata.
type Feedback ¶
type Feedback struct {
ID int64 `json:"id"`
PatternID string `json:"pattern_id"`
Rating int `json:"rating"`
WeightBefore float64 `json:"weight_before"`
WeightAfter float64 `json:"weight_after"`
EnabledBefore bool `json:"enabled_before"`
EnabledAfter bool `json:"enabled_after"`
Reverted bool `json:"reverted"`
CreatedAt string `json:"created_at"`
RevertedAt string `json:"reverted_at,omitempty"`
}
Feedback is one visible, reversible preference adjustment.
type ImportResult ¶
type ImportResult struct {
Kind string `json:"kind"`
Pattern *Pattern `json:"pattern,omitempty"`
Program *Program `json:"program,omitempty"`
GapsStripped int `json:"gaps_stripped"`
}
ImportResult distinguishes imported loops from finite programs.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library owns durable pattern/program rows in the app datastore.
func Open ¶
Open opens the library and seeds code-generated built-ins without replacing user names or feedback-derived weights. Retired built-ins are disabled on upgrade.
func OpenWithDatabase ¶
OpenWithDatabase borrows the process-owned datastore for pattern content.
func (*Library) ApplyFeedback ¶
ApplyFeedback records one thumbs adjustment and returns the visible row.
func (*Library) ApplyFeedbackContext ¶
func (l *Library) ApplyFeedbackContext(ctx context.Context, patternID string, rating int) (Feedback, Pattern, error)
ApplyFeedbackContext does not apply a queued adjustment after its caller loses authority or cancels the request.
func (*Library) AutoDisable ¶
AutoDisable reports the explicit opt-in setting.
func (*Library) CreatePattern ¶
func (l *Library) CreatePattern(input PatternInput) (Pattern, error)
CreatePattern validates, simplifies, and stores one shareable user pattern.
func (*Library) CreateProgram ¶
func (l *Library) CreateProgram(name, origin string, points []motion.CurvePoint, duration int64) (Program, error)
CreateProgram validates and stores finite motion content.
func (*Library) DeletePattern ¶
DeletePattern removes user/generated content; built-ins remain available.
func (*Library) DeleteProgram ¶
DeleteProgram removes one finite entry.
func (*Library) EnabledChoices ¶
func (l *Library) EnabledChoices() ([]CurationChoice, error)
EnabledChoices returns prompt-safe metadata, weighted preference first.
func (*Library) ExportPattern ¶
ExportPattern returns one individual shareable pattern file.
func (*Library) ExportProgram ¶
ExportProgram returns one individual finite program file.
func (*Library) FeedbackHistory ¶
FeedbackHistory returns newest entries first.
func (*Library) ListPatterns ¶
ListPatterns returns built-ins first, then user content by name.
func (*Library) ListPrograms ¶
ListPrograms returns finite content by name.
func (*Library) ResolveEnabled ¶
ResolveEnabled returns engine content only when the entry remains enabled.
func (*Library) SetAutoDisable ¶
SetAutoDisable updates the opt-in without changing any pattern immediately.
func (*Library) UndoFeedback ¶
UndoFeedback restores the exact prior weight/enablement when no newer feedback exists for that pattern.
func (*Library) UndoFeedbackContext ¶
UndoFeedbackContext keeps the ordering checks and both updates in the same cancelable transaction.
func (*Library) UpdatePattern ¶
func (l *Library) UpdatePattern(id string, patch PatternPatch) (Pattern, error)
UpdatePattern applies visible row controls and names; built-in curves remain immutable.
type Pattern ¶
type Pattern struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Origin string `json:"origin"`
Kind string `json:"kind"`
Enabled bool `json:"enabled"`
Deprecated bool `json:"deprecated,omitempty"`
Continuous bool `json:"continuous,omitempty"`
Weight float64 `json:"weight"`
CycleMillis int64 `json:"cycle_ms"`
Points []motion.CurvePoint `json:"points"`
// PreviewSamples are generated by the backend playback sampler and are not
// persisted as a second motion representation.
PreviewSamples []motion.CurvePoint `json:"preview_samples"`
Tags []string `json:"tags"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Pattern is one persisted library entry.
func (Pattern) Definition ¶
func (p Pattern) Definition() motion.PatternDefinition
Definition converts a stored row to engine-owned semantic content.
type PatternInput ¶
type PatternInput struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Kind string `json:"kind"`
CycleMillis int64 `json:"cycle_ms"`
Points []motion.CurvePoint `json:"points"`
Tags []string `json:"tags,omitempty"`
SimplifyError float64 `json:"simplify_error,omitempty"`
}
PatternInput is authoring/import content before persistence assigns an ID.
type PatternPatch ¶
type PatternPatch struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Kind *string `json:"kind,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Weight *float64 `json:"weight,omitempty"`
CycleMillis *int64 `json:"cycle_ms,omitempty"`
Points *[]motion.CurvePoint `json:"points,omitempty"`
Tags *[]string `json:"tags,omitempty"`
}
PatternPatch contains optional row/content changes.
type PreviewResult ¶
type PreviewResult struct {
Points []motion.CurvePoint `json:"points"`
Samples []motion.CurvePoint `json:"samples"`
CycleMillis int64 `json:"cycle_ms"`
OriginalCount int `json:"original_count"`
SimplifiedCount int `json:"simplified_count"`
}
PreviewResult returns the exact sparse curve and backend sampler output.
func PreviewPattern ¶
func PreviewPattern(input PatternInput) (PreviewResult, error)
PreviewPattern simplifies authored points, closes/floor-stretches the loop, and samples it with the same backend PCHIP implementation used for playback.
type Program ¶
type Program struct {
ID string `json:"id"`
Name string `json:"name"`
Origin string `json:"origin"`
DurationMillis int64 `json:"duration_ms"`
Points []motion.CurvePoint `json:"points"`
// PreviewSamples are generated by the backend playback sampler and are not
// persisted as a second motion representation.
PreviewSamples []motion.CurvePoint `json:"preview_samples"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Program is finite content kept distinct from repeatable patterns.
func (Program) Definition ¶
func (p Program) Definition() motion.ProgramDefinition
Definition converts a stored program to finite engine content.
type Snapshot ¶
type Snapshot struct {
Patterns []Pattern `json:"patterns"`
Programs []Program `json:"programs"`
Feedback []Feedback `json:"feedback"`
AutoDisable bool `json:"auto_disable"`
}
Snapshot is the backend-authoritative library workspace state.
type Summary ¶
type Summary struct {
Available bool `json:"available"`
PatternCount int `json:"pattern_count"`
EnabledPatternCount int `json:"enabled_pattern_count"`
ProgramCount int `json:"program_count"`
AutoDisable bool `json:"auto_disable"`
}
Summary is the compact polling state; large point arrays stay off /api/state.