Documentation
¶
Overview ¶
Package lessons defines the domain vocabulary, state transitions, text cleaning rules, and recall selection logic for repository-scoped lessons.
Index ¶
Constants ¶
const ( MaxTextBytes = 500 MaxRecallLessons = 8 MaxRecallBytes = 2048 MaxOpenPerRepository = 200 )
Domain bounds shared across storage, APIs, and recall selection.
Variables ¶
var ErrBadTransition = errors.New("lesson transition not permitted")
ErrBadTransition reports a state transition not permitted by the lesson lifecycle diagram.
Functions ¶
func CleanText ¶
CleanText validates and normalizes raw lesson text:
- Refuses lines starting with #, <!--, ```, or ~~~ (after optional leading whitespace).
- Collapses whitespace runs to single spaces and refuses empty text.
- Refuses text exceeding MaxTextBytes UTF-8 bytes.
- Refuses text where red.String detects any secret (without quoting it).
- Runs sanitize.Text, failing closed on Withheld and re-checking MaxTextBytes.
Types ¶
type Action ¶
type Action string
Action is a typed gesture or lifecycle event recorded on a lesson.
type Candidate ¶
type Candidate struct {
Number int
Version int
Text string
Class string
Paths []string
DataClass string
UpdatedAt time.Time
}
Candidate is an active lesson eligible for recall selection.
func Select ¶
func Select(c []Candidate, run RunContext) (chosen []Candidate, omitted int)
Select filters, ranks, and caps lesson candidates for run. Internal lessons are excluded from non-internal runs, and class-scoped lessons must match run.Class. Class-specific lessons rank ahead of general lessons, then newest UpdatedAt first (with Number descending as a deterministic tie-breaker). At most MaxRecallLessons lessons and MaxRecallBytes bytes of Text are chosen; oversized candidates are skipped whole while smaller subsequent ones may still fit.
type Refusal ¶
type Refusal string
Refusal is the closed error code for a refused lesson operation.
const ( TextEmpty Refusal = "text_empty" TextTooLong Refusal = "text_too_long" TextHasSecret Refusal = "text_has_secret" TextHasMarkup Refusal = "text_has_markup" LimitReached Refusal = "limit_reached" NotPermitted Refusal = "not_permitted" Disabled Refusal = "disabled" NoSuchLesson Refusal = "no_such_lesson" BadTransition Refusal = "bad_transition" )
Closed refusal codes.
type RefusedError ¶
RefusedError explains why a lesson operation was refused using a closed Refusal code.
type RunContext ¶
RunContext describes the run requesting lesson recall.
type State ¶
type State string
State is the lifecycle state of a repository lesson.