learn

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 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 learn is learning's first two stages (design 08 section 2): it collects the merged changes not yet learned from, finds the signals each one carries, and triages them into changes with a signal and changes with nothing to learn. A signal that needs a source Physa cannot read (no forge, no slice records, no session reader, or the engine, not built yet) is reported as not checked, never as absent. The signals in a change's sessions come from a Sessions reader; learn reads no session log and no store itself.

What is already learned is read from the record learning keeps (design 08 section 6): the Learned-through watermark, the newest default-branch change learned from, read from the learn branch and the default branch's history; and the Learned ids on the learn branch's unmerged commits and the collected changes. A run computes the next watermark and never moves it past a change not fully triaged. It spends no tokens and changes nothing; drafting proposals and writing the record happen elsewhere.

Index

Constants

View Source
const (
	// MatchedByTrailer is a session the change's Session trailer names.
	MatchedByTrailer = "trailer"
	// MatchedByTime is a session with a slice record in the change's window,
	// which no Session trailer names.
	MatchedByTime = "time"
)

How a session was joined to a change.

View Source
const (
	// KindCorrection is a review comment followed by a later commit in the
	// same PR: the review led to a fix, which may be a rule.
	KindCorrection = "correction"
	// KindArguedOptions is a long discussion among several people on a PR,
	// where options were argued: a decision, with the options rejected.
	KindArguedOptions = "argued-options"
	// KindRevert is a change that says it reverts another.
	KindRevert = "revert"
	// KindServedNotLoaded is a capability served by several changes whose
	// sessions never loaded its slice (design 07 section 4.1).
	KindServedNotLoaded = "served-not-loaded"
	// KindRecurringFinding is the same kind of finding recurring on one
	// capability (design 03 R4). Not built: the findings live in the
	// engine's records or team digests, and the engine does not exist yet,
	// so it is always reported as not checked.
	KindRecurringFinding = "recurring-finding"
	// KindAnsweredAsk is an ask in a session that the person answered: a
	// decision, with the options offered.
	KindAnsweredAsk = "answered-ask"
	// KindIntervention is a person's message sent mid-run in a session
	// (design 03 section 8): a correction, which may be a rule.
	KindIntervention = "intervention"
	// KindFixedFinding is a finding in a check's report that a later step
	// fixed: a later report of the same check in the same run passed, or
	// the finding is marked fixed.
	KindFixedFinding = "fixed-finding"
)

The kinds of Signal.

View Source
const (
	RuleReviewThenCommit = "review-then-commit"
	RuleLongDiscussion   = "long-discussion"
	RuleRevertMessage    = "revert-message"
	RuleServedNotLoaded  = "served-not-loaded"
	RulePersonAnswered   = "person-answered"
	RuleMidRun           = "message-mid-run"
	RuleFailThenPass     = "report-then-pass"
)

The rules that find each kind.

View Source
const (
	// DefaultChanges is how many of the newest changes are collected when no
	// starting change is given, so a first run on an old repo stays small.
	DefaultChanges = 50
	// CorrectionMinComments is how many review comments followed by a later
	// commit in the same PR make a correction.
	CorrectionMinComments = 1
	// ArguedMinComments is how many comments, review and discussion
	// together, a PR needs for its options to count as argued.
	ArguedMinComments = 3
	// ArguedMinPeople is how many distinct people those comments need.
	ArguedMinPeople = 2
	// UnloadedMinChanges is how many learned-from changes must serve a
	// capability without their sessions loading it before it is a signal.
	UnloadedMinChanges = 3
	// AnsweredAskMin is how many answered asks in a change's sessions make
	// a signal. A starting value, tuned from real runs.
	AnsweredAskMin = 1
	// InterventionMin is how many of a person's messages mid-run in a
	// change's sessions make a signal. A starting value, tuned from real
	// runs.
	InterventionMin = 1
	// FixedFindingMin is how many fixed findings in a change's sessions make
	// a signal. A starting value, tuned from real runs.
	FixedFindingMin = 1
)

The thresholds of triage, in one place. Each starts small and is tuned from real runs, never guessed further ahead (measure-before-budget, design 08 section 3).

View Source
const NoWatermark = "none"

NoWatermark is the Learned-through value of a record made before any change was learned through: the run started at the history's first change and the oldest it collected was not fully triaged. It names no change, so reading it gives no watermark, but it still marks the commit as a record.

View Source
const ResultVersion = 2

ResultVersion is the version of Result's JSON form.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeRef

type ChangeRef struct {
	Change  string `json:"change"`
	Short   string `json:"short"`
	Subject string `json:"subject"`
}

ChangeRef names a change.

type ChangeSignals

type ChangeSignals struct {
	ChangeRef
	Signals []Signal `json:"signals"`
	// Message is the change's full message, for drafting; not in the JSON form.
	Message string `json:"-"`
	// At is when the change was made, for drafting; not in the JSON form.
	At time.Time `json:"-"`
	// Capabilities are the values of the change's Capability trailers, for
	// drafting; not in the JSON form.
	Capabilities []string `json:"-"`
}

ChangeSignals is a change with the signals it carries.

type ChangeText

type ChangeText struct {
	Subject string
	Message string
}

ChangeText is a change's subject and full message.

type Incomplete

type Incomplete struct {
	ChangeRef
	Reason string `json:"reason"`
}

Incomplete is a change with no signal found whose forge signals could not be checked, so it is not known to have nothing to learn.

type Options

type Options struct {
	// Since is the change the run starts after; empty means after the
	// watermark, or the newest DefaultChanges changes when there is none.
	Since string
	// Forge is the forge to ask about each change's PR; nil means none.
	Forge forge.Forge
	// ForgeReason says why there is no forge, when Forge is nil.
	ForgeReason string
	// Records are the slice records, in any order.
	Records []store.SliceRecord
	// RecordsReason, when not empty, says why the slice records could not be
	// read; the signals that need them are then not checked.
	RecordsReason string
	// Capabilities are the slugs of the map's capabilities.
	Capabilities []string
	// Sessions finds the signals in each change's sessions; nil means none,
	// and the session kinds are then not checked.
	Sessions Sessions
}

Options are what a run reads besides version control.

type Quote

type Quote struct {
	// Author is who said it, as far as the log shows: "person" on an
	// answered ask, the reporting agent's name and label on a fixed finding.
	// The log does not prove who typed a message mid-run, so an
	// intervention's author never names a person.
	Author string
	At     time.Time
	Text   string
	// Options are the options an ask offered; empty for anything else.
	Options []string
	// Answer is the person's chosen option or own words, on an ask.
	Answer string
}

Quote is one thing said in a session that a session signal rests on.

type Result

type Result struct {
	Version int `json:"version"`
	// Range names the changes collected, as a range of version control.
	Range string `json:"range"`
	// Changes is how many changes are learned from: those collected, less
	// the ones already learned.
	Changes        int `json:"changes"`
	AlreadyLearned int `json:"already_learned"`
	// Forge names the forge asked about every change; empty when there was
	// none or it stopped answering.
	Forge       string        `json:"forge"`
	Unavailable []Unavailable `json:"unavailable"`
	// RecordsMissing is how many changes had no slice record in their window
	// and so do not count toward served-not-loaded.
	RecordsMissing int `json:"records_missing"`
	// SessionsRead is how many distinct sessions had their logs read.
	SessionsRead int `json:"sessions_read"`
	// SessionsUnavailable are the sessions behind a change whose logs could
	// not be read. They never hold the watermark back.
	SessionsUnavailable []SessionGap    `json:"sessions_unavailable"`
	Learn               []ChangeSignals `json:"learn"`
	Nothing             []ChangeRef     `json:"nothing"`
	Incomplete          []Incomplete    `json:"incomplete"`
	// Watermark is the full id of the change learning was read to have
	// learned through; empty when there is none.
	Watermark string `json:"watermark"`
	// Through is the full id of the change the next record learns through:
	// past every change triaged, never past one not fully triaged, and
	// never behind Watermark. With nothing triaged and no Watermark it is the
	// change the run started after; empty only when the run started at the
	// first change of the history.
	Through string `json:"through"`
	// LearnedNow are the run's changes with signals, by short id.
	LearnedNow []string `json:"learned_now"`
}

Result is one run's triage, newest change first in every list.

func Run

func Run(repo vcs.Repo, o Options) (Result, error)

Run collects the changes on the default branch not yet learned from, finds their signals and triages them. The error is for a history that cannot be read; a source of signals that cannot be read is reported in the Result.

type SessionGap

type SessionGap struct {
	// Change is the change's short id; Run sets it.
	Change  string `json:"change"`
	Session string `json:"session"`
	Reason  string `json:"reason"`
}

SessionGap is a session behind a change whose log could not be read. It never makes the change not fully triaged: session logs are an extra (design 08 section 5).

type Sessions

type Sessions interface {
	// Signals returns the signals in the sessions behind change c, each with
	// its Changes, Session and MatchedBy set, the ids of the sessions whose
	// logs it read, and a gap for each session whose log is unavailable.
	// recorded are the distinct sessions of the slice records in c's window;
	// after is the window's start, exclusive (zero means open), so the
	// window is (after, c's time].
	Signals(c vcs.Change, recorded []string, after time.Time) (signals []Signal, read []string, gaps []SessionGap)
}

Sessions finds the signals in the sessions behind a change (design 08 section 3). It reads the sessions the change's Session trailers name and, matched by time, those of recorded the trailers do not name.

type Signal

type Signal struct {
	Kind string `json:"kind"`
	Rule string `json:"rule"`
	// Changes are the short ids of the changes the signal is about: one for
	// the kinds found on a single change.
	Changes []string `json:"changes"`
	// Capability is the capability the signal is about, when it is about one.
	Capability string   `json:"capability,omitempty"`
	Evidence   []string `json:"evidence"`
	// Comments are the PR's comments, oldest first, on an argued-options
	// signal, for drafting; not in the JSON form.
	Comments []forge.Comment `json:"-"`
	// Reverted is the reverted change's subject and message, on a revert
	// signal whose reverted change is in the history, for drafting; not in
	// the JSON form.
	Reverted *ChangeText `json:"-"`
	// Session is the id of the session a session signal was found in.
	Session string `json:"session,omitempty"`
	// MatchedBy says how that session was joined to the change:
	// MatchedByTrailer or MatchedByTime.
	MatchedBy string `json:"matched_by,omitempty"`
	// Quotes are the words a session signal rests on, for drafting; not in
	// the JSON form, and never printed.
	Quotes []Quote `json:"-"`
}

Signal is one thing a change carries that the map may learn from (design 08 section 3): its kind, the rule that found it, the changes it is about and the evidence the rule saw.

type Unavailable

type Unavailable struct {
	Kind   string `json:"kind"`
	Reason string `json:"reason"`
}

Unavailable is a kind of signal that was not checked, and why.

Jump to

Keyboard shortcuts

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