learnbranch

package
v0.0.7 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: 15 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 learnbranch writes one learning run to the physa/learn branch (design 08 section 6): it rebuilds the branch on the default branch in an isolated working copy, applies the run's kept proposals there and commits them with the record of what was learned (the Learned-through watermark and the Learned ids). It pushes the branch with a lease, redoing the write once without a second agent session when someone else moved it, and opens or refreshes its one PR. It never touches the person's own working copy, index or checked-out branch, and never merges: stewards accept, edit or drop what the PR holds.

Index

Constants

View Source
const (
	PRNotAsked  = ""          // the run did not ask for a PR
	PRNone      = "none"      // nothing to open or refresh
	PROpened    = "opened"    // a PR was opened
	PRRefreshed = "refreshed" // the open PR's body was rebuilt
	PRReady     = "ready"     // no forge to open one; the branch is ready
)

The states of PR.

View Source
const Branch = "physa/learn"

Branch is the branch learning writes to.

Variables

This section is empty.

Functions

func Read

func Read(dir string, r vcs.Repo, lo learn.Options) (*mapfile.Map, learn.Result, error)

Read reads the map in dir and what the history r holds teaches it, with lo and its Capabilities taken from the map. It writes nothing.

func WriteRun

func WriteRun(stdout, stderr io.Writer, o Outcome, asJSON, branch bool) error

WriteRun prints a run for people or, with asJSON, as JSON: the Report on stdout and, when branch is true, what the run did to the branch after it (on stderr with asJSON, so stdout stays valid JSON).

func WriteText

func WriteText(w io.Writer, o Outcome) error

WriteText writes, for people, what the run did to the branch: the lines printed after the Report.

Types

type Commit

type Commit struct {
	ID      string
	Short   string
	Subject string
}

Commit is the change a run wrote to the branch.

type Flags

type Flags struct {
	Signals  bool
	Since    string
	JSON     bool
	Write    bool   // commit the kept proposals to physa/learn
	Push     bool   // push physa/learn; needs Write
	PR       bool   // open or refresh the PR; needs Push
	Appetite int64  // most tokens a draft session may use; zero is the default
	Agent    string // agent to draft with; empty is the default
	// contains filtered or unexported fields
}

Flags is a physa map learn command line as its declared flags read it.

func (*Flags) Declare

func (f *Flags) Declare(fs *pflag.FlagSet)

Declare declares the flags of physa map learn on fs and starts f afresh, so it runs once for every command line.

func (*Flags) Valid

func (f *Flags) Valid() bool

Valid reports whether the parsed line is a good one: --appetite a positive integer, no --appetite, --agent or --write with --signals, no --push without --write and no --pr without --push.

type Options

type Options struct {
	// Push pushes the branch to the default branch's remote, with a lease.
	Push bool
	// PR opens or refreshes the branch's PR; it needs Push.
	PR bool
	// Since is the change the run starts after; empty means after the
	// watermark (learn.Options.Since).
	Since string
	// Records are the slice records; RecordsReason, when not empty, says why
	// they could not be read.
	Records       []store.SliceRecord
	RecordsReason string
	// Session says how the run drafts and checks proposals.
	Session propose.Session
	// Sessions reads the session logs that join changes to their sessions;
	// nil means none.
	Sessions learn.Sessions
	// Forge is the forge to read each change's PR from; nil means none, and
	// ForgeReason says why.
	Forge       forge.Forge
	ForgeReason string
	// PRs opens and refreshes the branch's PR; nil means no forge to do it.
	PRs forge.PRs
}

Options say what one run reads and how far it goes. The map's capabilities are read from the working copy the run writes in.

type Outcome

type Outcome struct {
	// Report is what the run drafted and checked; its Kept are the proposals
	// applied to the branch and its Dropped every other one, with its reason.
	Report propose.Report
	// Result is the run's triage. After a redo its Through and LearnedNow are
	// the ones recorded.
	Result learn.Result
	// Commit is the change written to the branch; nil when nothing was.
	Commit *Commit
	// Pushed reports whether the branch was pushed.
	Pushed bool
	// Redone reports whether the write was redone after the lease was lost,
	// and Superseded how many applied proposals that dropped.
	Redone     bool
	Superseded int
	// PR is what happened to the branch's PR.
	PR PR
}

Outcome is what one run did.

func Run

func Run(ctx context.Context, w vcs.Writer, o Options) (Outcome, error)

Run writes one learning run to the branch with w: it refuses a branch checked out in any working copy, rebuilds the branch on the default branch in a working copy under the store, drafts from the copy's map, applies what is kept, commits when there is anything to record, and then pushes and opens or refreshes the PR as o asks. A session the circuit breaker stopped writes nothing and is no error (the Report's Session is SessionStopped). The Outcome holds what was done even when it returns an error.

type PR

type PR struct {
	State  string
	Number int
	URL    string
	// Reason says why there is no forge, for PRReady.
	Reason string
}

PR is what a run did with the branch's PR.

Jump to

Keyboard shortcuts

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