lessons

package
v0.59.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lessons defines the domain vocabulary, state transitions, text cleaning rules, and recall selection logic for repository-scoped lessons.

Index

Constants

View Source
const (
	MaxTextBytes         = 500
	MaxRecallLessons     = 8
	MaxRecallBytes       = 2048
	MaxOpenPerRepository = 200
)

Domain bounds shared across storage, APIs, and recall selection.

Variables

View Source
var ErrBadTransition = errors.New("lesson transition not permitted")

ErrBadTransition reports a state transition not permitted by the lesson lifecycle diagram.

Functions

func CleanText

func CleanText(raw string, red *redact.Redactor) (string, error)

CleanText validates and normalizes raw lesson text:

  1. Refuses lines starting with #, <!--, ```, or ~~~ (after optional leading whitespace).
  2. Collapses whitespace runs to single spaces and refuses empty text.
  3. Refuses text exceeding MaxTextBytes UTF-8 bytes.
  4. Refuses text where red.String detects any secret (without quoting it).
  5. Runs sanitize.Text, failing closed on Withheld and re-checking MaxTextBytes.

func ID

func ID(n int) string

ID formats a per-repository lesson sequence number as "L-<n>".

func ParseID

func ParseID(s string) (int, bool)

ParseID parses a strict "L-<n>" identifier matching ^L-[1-9][0-9]*$.

Types

type Action

type Action string

Action is a typed gesture or lifecycle event recorded on a lesson.

const (
	Teach       Action = "teach"
	Accept      Action = "accept"
	Edit        Action = "edit"
	Stop        Action = "stop"
	Resume      Action = "resume"
	NotRelevant Action = "not_relevant"
	Dismiss     Action = "dismiss"
	Codify      Action = "codify"
	Suspend     Action = "suspend"
	MakeDormant Action = "dormant"
)

Valid lesson actions.

func Actions

func Actions() []Action

Actions returns all valid lesson actions.

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

type RefusedError struct {
	Code   Refusal
	Detail string
}

RefusedError explains why a lesson operation was refused using a closed Refusal code.

func (*RefusedError) Error

func (e *RefusedError) Error() string

Error implements error.

type RunContext

type RunContext struct {
	DataClass string
	Class     string
}

RunContext describes the run requesting lesson recall.

type State

type State string

State is the lifecycle state of a repository lesson.

const (
	Active    State = "active"
	Proposed  State = "proposed"
	Stopped   State = "stopped"
	Suspended State = "suspended"
	Dormant   State = "dormant"
	Codified  State = "codified"
	Dismissed State = "dismissed"
)

Valid lesson states.

func States

func States() []State

States returns all valid lesson states.

func Transition

func Transition(from State, a Action) (State, error)

Transition applies action a to state from and returns the resulting state, or ErrBadTransition if the move is not permitted. Teach creates a lesson and NotRelevant keeps its state.

Jump to

Keyboard shortcuts

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