Documentation
¶
Overview ¶
Package brief previews each pull request with one headless call of the agent: goal, context, kind, size, risk and open questions.
Index ¶
- Constants
- Variables
- func Due(pr dinv.PR, rec dinv.BriefRecord, ok bool, version string, now time.Time, ...) bool
- func InputSHA(head, settings string, in Input) string
- func Prompt(taxonomy, vocabulary string, in Input) string
- func Version(taxonomy string) string
- type AskRunner
- type Brief
- type Call
- type Deps
- type Input
- type Intakes
- func (a Intakes) Changed(u unit.Unit) (<-chan struct{}, func())
- func (a Intakes) Peek(ctx context.Context, u unit.Unit, first bool) (intake.Readiness, error)
- func (a Intakes) Ready(ctx context.Context, u unit.Unit, first bool) (intake.Readiness, error)
- func (a Intakes) Unwant(ctx context.Context, u unit.Unit) error
- type Queue
- func (q *Queue) Attempt(ctx context.Context, ref github.Ref) (int, error)
- func (q *Queue) AttemptOf(pr dinv.PR, rec dinv.BriefRecord) int
- func (q *Queue) Breaker() (open bool, since time.Time, lastErr string, next time.Time)
- func (q *Queue) Briefed(ctx context.Context) (map[github.Ref]Summary, map[github.Ref]dinv.BriefRecord, error)
- func (q *Queue) Changed(ref github.Ref) (<-chan struct{}, func())
- func (q *Queue) Due() <-chan struct{}
- func (q *Queue) Forget(ctx context.Context, ref github.Ref) error
- func (q *Queue) Interrupted(ctx context.Context) error
- func (q *Queue) Next(states []inventory.BriefState, now time.Time) (next time.Time, ok bool)
- func (q *Queue) Peek(ctx context.Context, ref github.Ref, first bool) (Readiness, error)
- func (q *Queue) Ready(ctx context.Context, ref github.Ref, first bool) (Readiness, error)
- func (q *Queue) RefreshIfStale(ctx context.Context, pr dinv.PR) error
- func (q *Queue) Run(ctx context.Context) (string, error)
- func (q *Queue) Start(ctx context.Context)
- func (q *Queue) Status(ctx context.Context) (Status, error)
- func (q *Queue) Touched(refs []pr.Ref)
- func (q *Queue) Unwant(ctx context.Context, ref github.Ref) error
- func (q *Queue) Views(ctx context.Context, prs ...dinv.PR) (map[github.Ref]*View, error)
- type Readiness
- type ReadyState
- type Result
- type RunStore
- type Source
- type Status
- type Store
- type Summary
- type View
Constants ¶
const ( // BreakerAfter consecutive global failures, across pull requests, open // the breaker. BreakerAfter = 3 // BreakerCool is how long the breaker stays open before a trial. BreakerCool = 15 * time.Minute )
const ( KindBreakerOpened = "brief_breaker_opened" KindBreakerClosed = "brief_breaker_closed" KindBreakerTrialFailed = "brief_breaker_trial_failed" )
Events of the breaker, on no pull request, keyed by the time: Data is the error that opened it, the trial run that closed it, or the error of a trial that kept it open.
const ( // Batch, Concurrency and CallTimeout bound what one run spends. Batch = 5 Concurrency = 2 CallTimeout = 3 * time.Minute // RefreshFiles is how many files a new head must add before the brief // is made again. RefreshFiles = 5 // BodyQuiet is how long an edited description must sit unchanged before // the background job briefs it again. BodyQuiet = 10 * time.Minute )
const ( OutcomeOK = "ok" OutcomeFailed = "failed" OutcomeUnfit = "unfit" OutcomeOverBudget = "over-budget" OutcomeTooLong = "too-long" OutcomeTimeout = "timeout" // OutcomeReused is a run whose input hash matched the brief in use: no // diff read and no agent call. OutcomeReused = "reused" // token or the budget. OutcomeUnavailable = "unavailable" )
Outcomes of a brief run besides the store's running and interrupted.
const ( // TriggerBackground is a run the brief job started on its own. TriggerBackground = "background" // TriggerWanted is a run a first turn waits on. TriggerWanted = "wanted" // TriggerRefresh is a run a later turn started for a stale brief. TriggerRefresh = "refresh" // TriggerTrial is the breaker's run that tells whether briefs work again. TriggerTrial = "trial" )
Triggers of a brief run.
const ( // MaxFailures failures of a wanted brief that belong to its pull // request, on one attempt_of, give it up. MaxFailures = 3 WantedTimeout = 30 * time.Second // SessionWait is how long a turn asked for inside an agent session waits // for its brief, under the 2 minutes an agent's shell tool allows. SessionWait = 90 * time.Second )
const ( WaitBriefing = intake.WaitBriefing WaitRetry = intake.WaitRetry )
The waits of a Readiness.
const ( ReasonOff = "briefs are off" ReasonNone = "this pull request has no brief yet" )
const Resync = 10 * time.Minute
Resync is how long Start sleeps when no deadline waits: a change nothing announced is found within it.
const VocabularySize = 30
VocabularySize is how many values of each open tag key the prompt lists.
const WantedConcurrency = 2
WantedConcurrency bounds the runs started outside Run.
Variables ¶
var DefaultTaxonomy string
var ErrInvalid = errors.New("the brief does not fit the schema")
var Schema string
WantedRetry is the wait before the second and the third attempt of a wanted brief.
Functions ¶
func Due ¶
func Due(pr dinv.PR, rec dinv.BriefRecord, ok bool, version string, now time.Time, retry time.Duration) bool
Due says whether the pull request needs a brief now: none yet, a failed one that changed or whose wait is over, or a brief the pull request moved past. A new prompt version alone is not due: the brief in use stays until a turn asks for it.
func InputSHA ¶
InputSHA hashes what a brief is made from, the head included: the facts with every task-list box read as unticked, so ticking one changes nothing. settings are the other inputs of the call that the version does not cover.
Types ¶
type Brief ¶
type Brief struct {
Goal string `json:"goal"`
Context string `json:"context"`
Kind string `json:"kind"`
Size string `json:"size"`
Risk string `json:"risk"`
RiskWhy string `json:"risk_why"`
OpenQuestions []string `json:"open_questions"`
// Tags are the normalized key:value tags.
Tags []string `json:"tags"`
}
type Deps ¶
type Deps struct {
Store Store
Source interface {
Facts(ctx context.Context, ref github.Ref) (Input, error)
Diff(ctx context.Context, ref github.Ref, max int) (diff string, cut bool, err error)
}
Runner interface {
Run(ctx context.Context, c Call) (Result, error)
}
// Enabled is brief.enabled: false answers every Ready without a brief.
Enabled bool
// Taxonomy is the bundled one until profiles exist; see the step 2 seam.
Taxonomy func(ref github.Ref) string
// Home is the agent home a pull request's brief runs with.
Home func(ref github.Ref) string
Tier turns.Tier
MaxDiffBytes int
// Retry is how long a background failure waits before the next try:
// sweep.slow, doubled after each failure.
Retry time.Duration
// Allow is false while the GitHub budget refuses reads of that
// priority; nil means fine.
Allow func(dgh.Priority) bool
// CallTimeout and WantedTimeout bound reading the input and the call
// together, of a background and of a wanted run; zero means the
// package's constant.
CallTimeout, WantedTimeout time.Duration
Now func() time.Time
// After is time.After unless set.
After func(time.Duration) <-chan time.Time
// Changes keeps Status's counts until a pull request, a brief or the
// configuration changes, or the minute turns; nil reads every call.
Changes port.Changes
Log func(format string, args ...any)
}
type Input ¶
type Input struct {
Title, Body, Issue string
Files []string
Diff string
// DiffNote says why the diff is cut or missing, "" when it is whole.
DiffNote string
// Paths are the changed files, at most filesMax.
Paths []string
// DiffBytes is the whole diff's size, 0 when gh did not return it.
DiffBytes int
DiffCut bool
}
type Intakes ¶
type Intakes struct{ Q *Queue }
Intakes is the queue as the intake's Briefs port.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
func (*Queue) AttemptOf ¶
AttemptOf is Attempt with the pull request and its brief record already read.
func (*Queue) Breaker ¶
Breaker is the state the health and the menu bar show; open is false while it is closed.
func (*Queue) Briefed ¶
func (q *Queue) Briefed(ctx context.Context) (map[github.Ref]Summary, map[github.Ref]dinv.BriefRecord, error)
Briefed reads every brief record in one query, with the summary of each stored brief; a pull request whose brief is missing or does not fit the schema has no summary.
func (*Queue) Changed ¶
Changed is closed by the next end of a brief run of ref after the call; the func releases it.
func (*Queue) Due ¶
func (q *Queue) Due() <-chan struct{}
Due is signaled when followed pull requests are due a background brief.
func (*Queue) Forget ¶
Forget drops the brief in use and any give-up, so the next run makes it again; every run stays.
func (*Queue) Interrupted ¶
Interrupted ends the runs a daemon that stopped mid-call left running.
func (*Queue) Next ¶
Next is the earliest time the queue has something to do with states: the breaker's trial while it is open, else the retry of a wanted brief and the end of a failed background brief's backoff and the end of an edited description's quiet period. ok is false when nothing waits.
func (*Queue) Peek ¶
Peek is Ready's answer without starting a brief, waiting or writing: a plan reads it to say whether a round would go now.
func (*Queue) Ready ¶
Ready answers for a turn of ref. A first turn waits for a brief at the current version, and its wanting one starts that brief at once; a later turn takes the brief there is, stale or not, starts a refresh when one is due, and never waits.
func (*Queue) RefreshIfStale ¶
RefreshIfStale starts one refresh of pr's brief when it is stale and due; View alone never starts a run.
func (*Queue) Run ¶
Run briefs up to Batch due pull requests, Concurrency at a time, leaving out the wanted ones and the ones in flight.
func (*Queue) Start ¶
Start runs wanted briefs and the breaker's trials until ctx ends, waking at the earliest deadline, on Touched and on the end of a run, and after Resync at most.
func (*Queue) Status ¶
Status counts the followed pull requests by brief state, read again only after a note of statusInputs or when the minute turns.
func (*Queue) Touched ¶
Touched wakes the scheduler for pull requests whose inputs changed; any number of calls before it scans make one scan.
type Readiness ¶
type Readiness struct {
State ReadyState
Wait string
Attempt int
LastError string
Next, Since time.Time
Reason string
Cause string
Brief *Brief
Run int64
}
Readiness answers whether a turn goes now. Ready carries Brief, made by Run. Wait names what the turn waits on: Attempt is the attempt it waits for, LastError the failure of the one before, Next the retry's time. Without says why in Reason, and Cause names a give-up (Attempt failures, the last LastError), an open breaker (since Since, for LastError) or briefs that are disabled.
type ReadyState ¶
type ReadyState string
const ( Ready ReadyState = "ready" Wait ReadyState = "wait" Without ReadyState = "without" )
type RunStore ¶
type RunStore interface {
StartBriefRun(ctx context.Context, r dinv.BriefRun) (int64, error)
EndBriefRun(ctx context.Context, r dinv.BriefRun, st dinv.BriefRecord) error
InterruptBriefRuns(ctx context.Context, at time.Time) (int, error)
RefreshBrief(ctx context.Context, ref github.Ref) error
WantBrief(ctx context.Context, ref github.Ref, at time.Time) error
ClearWanted(ctx context.Context, ref github.Ref) error
RecordEvent(ctx context.Context, ev dinv.Event) error
}
type Source ¶
Source reads a brief's input through the GitHub client: one GraphQL call for the facts under 100 files, and one REST call for the diff.
type Store ¶
type Store interface {
BriefStates(ctx context.Context) ([]inventory.BriefState, error)
PR(ctx context.Context, ref github.Ref) (dinv.PR, bool, error)
BriefRecords(ctx context.Context, refs ...github.Ref) (map[github.Ref]dinv.BriefRecord, error)
BriefRecord(ctx context.Context, ref github.Ref) (dinv.BriefRecord, bool, error)
TagVocabulary(ctx context.Context, owner string, keys []string, limit int) (map[string][]tag.Count, error)
RunStore
}
type Summary ¶
type Summary struct {
Kind string `json:"kind"`
Size string `json:"size"`
Risk string `json:"risk"`
Goal string `json:"goal"`
OpenQuestions int `json:"open_questions"`
// Tags are the brief's key:value tags, sorted.
Tags []string `json:"tags"`
}
Summary is what a row of the list shows of a brief.