Documentation
¶
Overview ¶
Package draft reads a routine's draft as the builder edits it, before it is saved: its spec as Save stores it, the problems that keep it from being saved, its warnings, the steps this build runs only in Dry run, and its sentence. The autopilot package's Describe and Save read a draft here, and so does whatever checks a routine outside the app's own process, so a routine reads the same wherever it is checked.
It is a pure leaf. What a draft's checks read beyond the draft (the prompt library, the user's scripts, and the starter prompts' names) comes through Setup, which the caller adapts, and what this build runs through Offers. It reads no database, starts nothing, and never asks GitHub.
Index ¶
- Constants
- Variables
- func ActsOn(sp spec.Spec) []item.Kind
- func CheckDescription(desc string) (string, error)
- func CheckName(name string) (string, error)
- func CheckTemplate(key string) (string, error)
- func Encode(sp spec.Spec) ([]byte, spec.Spec, error)
- func FindScript(mine []Script, step spec.ScriptStep) (int, bool)
- func FitName(name, suffix string) string
- func FreeName(name string, taken func(string) bool) string
- func HasStep(sp spec.Spec, kind catalog.StepKind) bool
- func Hidden(r rune) bool
- func KindsWords(kinds []item.Kind) string
- func Load(sp spec.Spec) (spec.Spec, []spec.Problem, error)
- func Message(err error) string
- func NameKey(name string) string
- func NeedsWords(needs []string) string
- func OnlySearches(w spec.Watch) bool
- func Problems(ctx context.Context, sp spec.Spec, s Setup, o *Offers) []spec.Problem
- func PromptIndex(library []Prompt, ref spec.PromptRef) int
- func RenamedWords(picked, name string) string
- func Series(words []string) string
- func Stamp(library []Prompt, mine []Script, sp *spec.Spec) bool
- func Stamped(library []Prompt, mine []Script, sp spec.Spec) (spec.Spec, []byte, bool)
- func StepPromptProblems(library []Prompt, st spec.Step, kinds []item.Kind, field string) []spec.Problem
- func TriageSteps() []catalog.StepKind
- type Offers
- func (o *Offers) ModeFor(mode autopilotprefs.Mode, s spec.Spec) autopilotprefs.Mode
- func (o *Offers) Needs(s spec.Spec) []string
- func (o *Offers) NotOffered(s spec.Spec) []catalog.StepKind
- func (o *Offers) OrCatalog() *Offers
- func (o *Offers) PlaceWords() string
- func (o *Offers) PreferredPlace() catalog.Where
- func (o *Offers) RunsAt(place catalog.Where) bool
- type Prompt
- type Reading
- type ReplyFor
- type Script
- type Setup
Constants ¶
const ( // MaxNameRunes caps a routine's name. MaxNameRunes = 80 // MaxDescriptionRunes caps a routine's description. MaxDescriptionRunes = 500 )
const PastRulesOff = "Let routines merge your own pull requests past the rules is off in Autopilot's settings: " +
"until you turn it on, this step merges only what GitHub allows."
PastRulesOff is the warning of a Merge it that allows going past the rules while the user's switch for it is off.
Variables ¶
var ( // ErrInvalidName is returned for a name that is empty, too long, or not one line. ErrInvalidName = errors.New("invalid routine name") // ErrInvalidDescription is returned for a description that is too long or holds a // control character. ErrInvalidDescription = errors.New("invalid routine description") // ErrInvalidTemplate is returned for a template key that isn't one. ErrInvalidTemplate = errors.New("invalid template key") )
Functions ¶
func ActsOn ¶
ActsOn returns the kinds of item a routine acts on: those both its watch and its trigger take.
func CheckDescription ¶
CheckDescription returns a routine's description, trimmed, refusing one longer than MaxDescriptionRunes or holding a control character but a line break.
func CheckName ¶
CheckName returns a routine's name, trimmed, refusing one that is empty, longer than MaxNameRunes, or not one line of plain text.
func CheckTemplate ¶
CheckTemplate returns a template's key, trimmed, refusing one that isn't one: "" is none.
func Encode ¶
Encode returns the draft spec sp as Save stores it, compact JSON in the format's order, and the spec it encodes: normalized, at this build's version when it names none. Load, and the autopilot package's Save, read a draft's spec as it encodes here.
func FindScript ¶
func FindScript(mine []Script, step spec.ScriptStep) (int, bool)
FindScript returns the index in mine of the script step names, -1 for none, and whether it waits to be picked again. The script with the step's UUID is the step's, whatever its ID and name are now. Otherwise, as for a step picked before UUIDs, the script with the step's ID is, but saved under another name than the step's it is renamed, and waits: an ID alone may since name another script.
func FitName ¶
FitName returns name with suffix, name cut so the whole fits MaxNameRunes and trimmed where it was cut.
func FreeName ¶
FreeName returns name, or, when taken says another routine has it, the first of "name 2", "name 3", and so on that taken says none has, each cut to fit MaxNameRunes (FitName): the name a save, a copy, an import, or a restore gives a routine whose name is taken. taken compares names as NameKey does, and says no to all but a finite few.
func Hidden ¶
Hidden reports a rune that can't be shown in a line of text: a control character, or one that changes the text's direction.
func KindsWords ¶
KindsWords names kinds of item: "pull requests", "issues", "pull requests and issues".
func Load ¶
Load reads the draft spec sp as Save stores it (Encode), loaded back as every load checks a stored spec: the spec loaded, or, with the spec's own problems, normalized. A spec that can't be read at all, as one past the size a spec may be, is an error.
func Message ¶
Message returns what a refusal from one of the draft's checks says to the user: the sentence CheckName, CheckDescription, CheckTemplate, or Read words it with, as the window shows it (uierr.Message). A caller that words a draft's problems for someone other than the window, as a check of a proposed routine does for the agent that proposed it, reads them here.
func NameKey ¶
NameKey folds a routine's name for comparing it with another, ignoring case: each rune is replaced by the smallest rune it folds to under Unicode's simple case folding, so two names have one key exactly when strings.EqualFold says they are the same. Every comparison of names, in Go and in the database's uniqueness (name_key), uses it, since SQLite's NOCASE folds ASCII alone.
func NeedsWords ¶
NeedsWords says what a template needs (Needs) as a sentence, "" for nothing.
func OnlySearches ¶
OnlySearches reports a watch whose sources are all searches.
func Problems ¶
Problems returns the problems Save refuses the loaded spec sp for beyond the spec's own: an agent step set to run where this build can't run one (o's places), a background agent step whose own agent can't keep its tools preset, the prompts its steps name that s's library doesn't have or that don't fit, and the scripts they name that the user no longer has under that name. Without a library, or scripts, to read, it finds none of theirs. The list is never nil.
func PromptIndex ¶
PromptIndex returns the index in library of the prompt ref names, -1 for none: the one with its UUID, whatever it is called now; else, as a ref from before UUIDs or from another library names one, the user's copy of a starter, or the one with a nickname, ignoring case. The item's own default names no library prompt.
func RenamedWords ¶
RenamedWords says that the script a step picked as picked is now saved as name, so it waits to be picked again.
func Series ¶
Series joins words as a sentence lists them: "a", "a and b", "a, b, and c"; no words are "its steps".
func Stamp ¶
Stamp writes into sp, in place, what each prompt and script its steps name is now in library and in mine, wherever the reference resolves (PromptIndex, FindScript): the record's UUID, so the reference finds it whatever it is called next, and its fallback brought up to date, a prompt's nickname, or its starter's key while the prompt is still that starter's copy, and a script's ID and name. A reference that resolves to nothing, and a script step that waits to be picked again, are left as they are, and nothing is ever written as "". It reports whether it changed sp.
func Stamped ¶
Stamped returns a copy of sp stamped (Stamp), as it loads back, and encoded as it is stored, when stamping changed anything and the copy still loads, within spec.MaxBytes; otherwise sp, no text, and false, so the caller keeps what it has.
func StepPromptProblems ¶
func StepPromptProblems(library []Prompt, st spec.Step, kinds []item.Kind, field string) []spec.Problem
StepPromptProblems returns the problems of the prompts one step, at field, names, against library, for a routine that acts on kinds: an agent step's prompt (the item's own default needs no check), and a GitHub step's replies.
func TriageSteps ¶
TriageSteps are the steps that change only how an item shows in the inbox.
Types ¶
type Offers ¶
type Offers struct {
Steps []catalog.StepKind
Actions []catalog.GitHubActionKind
// Places are where this build runs an agent step (catalog.PlaceInfo.Offered). A step
// set to run anywhere else is a problem the builder shows (placeProblems), so it is
// never saved; and one a routine holds from before keeps its runs from starting, as
// this Mac isn't ready for it (the autopilot package's readiness).
Places []catalog.Where
}
Offers names the kinds of step, and the GitHub actions, a build runs: by default the catalog's own (Step.Offered, GitHubAction.Offered), which each part's phase turns on once its dispatcher is built. A test hands in its own, with fakes for the dispatchers, never by changing the catalog. A nil *Offers is the catalog's.
func CatalogOffers ¶
func CatalogOffers() *Offers
CatalogOffers returns the catalog's own offers: each kind of step, GitHub action, and place it marks offered.
func (*Offers) ModeFor ¶
func (o *Offers) ModeFor(mode autopilotprefs.Mode, s spec.Spec) autopilotprefs.Mode
ModeFor returns mode, or Dry run for a spec with a step this build can't run yet.
func (*Offers) Needs ¶
Needs names each part of s this build can't run yet, in plain words, as a template shows them: an agent's place, then each kind of step and GitHub action it doesn't offer, in the catalog's order. The list is never nil.
func (*Offers) NotOffered ¶
NotOffered returns the kinds of step s has that this build can't run yet, in the catalog's order: a step whose kind isn't offered, and a GitHub step with an action that isn't. The list is never nil.
func (*Offers) PlaceWords ¶
PlaceWords names the places this build runs an agent in: "In my terminal".
func (*Offers) PreferredPlace ¶
PreferredPlace is where a routine made from an item runs its agent: in the background once this build runs agents there, else the first place it does.
type Prompt ¶
type Prompt struct {
UUID string
Starter string
Nickname string
// Reply reports a review reply, which a GitHub step comments, rather than a prompt an
// agent runs.
Reply bool
// ReplyFor is the review a reply is written for: an approval, a request for changes,
// or a comment. A GitHub step only comments (D5), so it posts a comment's reply alone,
// never an approving one such as LGTM, whose words would read as an approval.
ReplyFor ReplyFor
// Kinds are the kinds of item it applies to.
Kinds []item.Kind
}
Prompt is one of the library's prompts as a routine names it: by its UUID, else the starter it came from, else its nickname.
type Reading ¶
type Reading struct {
// Spec is the draft's spec as Save stores it: normalized, and as it loads back once it
// loads.
Spec spec.Spec
// Sentence says the draft in one sentence, as the routine list will; "" while it has
// problems, so the builder keeps the last one that read.
Sentence string
// Problems are what keeps it from being saved, each where it is in the spec; never nil.
Problems []spec.Problem
// Warnings are what may make it do less than meant, or more than is wise, each where
// it is; none keeps it from being saved, and the list is never nil.
Warnings []spec.Problem
// DryRunOnly are the kinds of step it has that this build can't run yet, so it runs
// in Dry run alone, whatever its mode; never nil.
DryRunOnly []catalog.StepKind
}
Reading is a draft as the builder shows it before it is saved, with its spec as Save stores it.
func Read ¶
func Read(ctx context.Context, sp spec.Spec, mode autopilotprefs.Mode, s Setup, o *Offers) (Reading, error)
Read reads the draft spec sp, whose routine acts in mode, as the builder shows it while it is edited: its spec as Save stores it (Load), the problems Save would refuse it for (the spec's own, else Problems'), the steps this build runs only in Dry run (o's), its warnings, and, only while it has no problem, its sentence. It saves nothing and never asks GitHub: beyond the draft it reads s's library, its scripts for a script step, for a Merge it past the rules whether the user's switch allows it, and, for the sentence, its starter prompts' names. A spec that can't be read at all, as one past the size a spec may be, is an error.
type ReplyFor ¶
type ReplyFor string
ReplyFor is the review a library reply is written for, as the prompt library names it.
type Script ¶
Script is one of the user's own Repo scripts as a script step names it: its UUID, its ID on this Mac, and the name it is saved under now.
type Setup ¶
type Setup interface {
// Library returns the prompt library, false when there is none or it can't be read,
// which skips the prompt checks.
Library(ctx context.Context) ([]Prompt, bool)
// Scripts returns the user's own Repo scripts, read only for a spec with a script
// step: false when there are none to read or they can't be read, which skips the
// script checks.
Scripts(ctx context.Context) ([]Script, bool)
// StarterNames names the starter prompts in the sentence, as the library names them;
// nil writes a starter's key as words.
StarterNames(ctx context.Context) spec.PromptNames
// PastRules reports Let routines merge your own pull requests past the rules switched
// on in Autopilot's settings; false when it is off or can't be read, which warns of a
// Merge it that allows it.
PastRules(ctx context.Context) bool
}
Setup is what a draft's checks read beyond the draft itself. A read can fail, as a library that can't be read does: the checks it answers are then skipped, and the engine checks a step's prompt, and its script, again right before each start.