Documentation
¶
Overview ¶
Package propose is learning's fourth stage (design 08 section 2): every proposed map entry is checked against the signals it claims and, on a scratch copy of the map, with the map check; those that pass are kept and every other one is dropped with its reason, never silently. It writes the map only through ApplyAll, to the root it is given, and never in Check.
Index ¶
- Constants
- func ApplyAll(root string, b draft.Batch, kept []Kept, o Options) ([]Kept, []Dropped)
- func Check(root string, b draft.Batch, ps []draft.Proposal, o Options) ([]Kept, []Dropped)
- func WriteJSON(w io.Writer, r Report) error
- func WriteMarkdown(w io.Writer, r Report) error
- type Dropped
- type Kept
- type Options
- type Report
- type Session
Constants ¶
const ( KindRule = "rule" KindDecision = "decision" KindQuestion = "question" KindPromise = "promise" )
The kinds of proposal, and the section each names: a kind file's word, or the promise in index.md's front matter.
const ( SessionNone = "none" SessionRan = "ran" SessionStopped = "stopped" )
The values of Report.Session.
const ReportVersion = 1
ReportVersion is the version of Report's JSON form. It changes only when a field changes meaning or goes away.
Variables ¶
This section is empty.
Functions ¶
func ApplyAll ¶
ApplyAll applies each of kept, in order, to the map under root itself and returns those applied and those dropped. After each one it runs the map check against the problems the map had before that proposal; one that adds a problem, or does not read back as exactly one new entry citing its changes, is undone and dropped with its reason. It writes only the map's files under root's .physa/.
func Check ¶
Check checks each of ps, in order, against b and the map under root (the repo root), and returns those kept and those dropped: every proposal is in exactly one of the two. A proposal is first checked for what it claims (its kind and section, its capability, its signal and changes, its entry); then it is applied alone to a scratch copy of the map and kept only when the map check finds no problem the map did not have already, the capability's kind file holds exactly one more entry of its kind, and that entry's anchors cite one of its changes. Nothing under root is written.
Types ¶
type Dropped ¶
type Dropped struct {
// Proposal is the proposal as the session wrote it; zero for an item
// that was not a proposal.
Proposal draft.Proposal `json:"proposal"`
// Raw is an item that was not a proposal, as the session wrote it.
Raw string `json:"raw,omitempty"`
Reason string `json:"reason"`
}
Dropped is a proposal, or an item of the session's output that was not one, left out with its reason.
func FromMalformed ¶
FromMalformed turns the items draft.Parse could not read as proposals into Dropped, each with its reason.
type Kept ¶
type Kept struct {
Proposal draft.Proposal `json:"proposal"`
// Slug is the new entry's slug; empty for a promise.
Slug string `json:"slug"`
}
Kept is a proposal that passed every check.
type Options ¶
type Options struct {
// OpenRepo opens the version control holding the repo, for commit
// anchors. Nil leaves them unresolved, as in mapcheck.
OpenRepo func(root string) (vcs.Repo, error)
// PRExists tells whether a PR with this number exists. Nil checks #N
// anchors for form only.
PRExists func(n int) (bool, error)
}
Options carries what the map check cannot learn from the map's files.
type Report ¶
type Report struct {
Version int `json:"version"`
// Range is the range of changes the run read.
Range string `json:"range"`
// Changes is how many changes carry the batch's signals, Signals how
// many signals the batch holds, and Capabilities how many capabilities
// it bears on.
Changes int `json:"changes"`
Signals int `json:"signals"`
Capabilities int `json:"capabilities"`
// Session is SessionNone when no session started, SessionStopped when
// the circuit breaker stopped it, and SessionRan otherwise.
Session string `json:"session"`
// DraftSession is the id of the draft's agent session, empty when none ran.
DraftSession string `json:"draft_session"`
Appetite int64 `json:"appetite"`
Tokens adapter.Tokens `json:"tokens"`
Kept []Kept `json:"kept"`
Dropped []Dropped `json:"dropped"`
}
Report is what one run of learning's draft and check stages found.
func Run ¶
func Run(ctx context.Context, root string, m *mapfile.Map, res learn.Result, s Session) (Report, error)
Run is learning's draft and check stages end to end: it batches the signals of res, drafts proposals from them with one agent session and checks them on a scratch copy of the map under root. With no signals no agent is resolved and the Report's Session is SessionNone. It returns an error when the agent cannot be resolved or fails; the circuit breaker stopping the session is not one (the Session is SessionStopped, with nothing kept). It writes nothing to the map.
type Session ¶
type Session struct {
// Agent resolves the agent to draft with. Run calls it only when there
// are signals to draft from.
Agent func() (adapter.Adapter, error)
// Appetite is the most tokens the session may use; zero means
// draft.DefaultAppetite.
Appetite int64
// Progress receives one line before the session starts; nil drops it.
Progress io.Writer
// Check is passed to Check.
Check Options
// Person is the name of the person running Physa, or empty when unknown;
// the draft prompt names them.
Person string
}
Session says how Run drafts.