brief

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 31 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 brief previews each pull request with one headless call of the agent: goal, context, kind, size, risk and open questions.

Index

Constants

View Source
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
)
View Source
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.

View Source
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
)
View Source
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"
	// OutcomeUnavailable is the agent unavailable, or GitHub refusing the
	// token or the budget.
	OutcomeUnavailable = "unavailable"
)

Outcomes of a brief run besides the store's running and interrupted.

View Source
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.

View Source
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
)
View Source
const (
	WaitBriefing = intake.WaitBriefing
	WaitRetry    = intake.WaitRetry
)

The waits of a Readiness.

View Source
const (
	ReasonOff  = "briefs are off"
	ReasonNone = "this pull request has no brief yet"
)
View Source
const Resync = 10 * time.Minute

Resync is how long Start sleeps when no deadline waits: a change nothing announced is found within it.

View Source
const VocabularySize = 30

VocabularySize is how many values of each open tag key the prompt lists.

View Source
const WantedConcurrency = 2

WantedConcurrency bounds the runs started outside Run.

Variables

View Source
var DefaultTaxonomy string
View Source
var ErrInvalid = errors.New("the brief does not fit the schema")
View Source
var Schema string
View Source
var WantedRetry = []time.Duration{time.Minute, 4 * time.Minute}

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

func InputSHA(head, settings string, in Input) string

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.

func Prompt

func Prompt(taxonomy, vocabulary string, in Input) string

Prompt fills the template in one pass, so a "{{...}}" inside the pull request's own text stays as it is. The data markers carry a hash of the data, so the pull request cannot close its own block. The vocabulary is not part of Version, so a new tag value makes no brief stale.

func Version

func Version(taxonomy string) string

Version keys the cache: a new prompt, schema or taxonomy makes every brief stale.

Types

type AskRunner

type AskRunner struct{ Asker turns.Asker }

AskRunner makes a brief with one headless call of the agent.

func (AskRunner) Run

func (a AskRunner) Run(ctx context.Context, c Call) (Result, error)

Run returns, with a failure, what the call cost when the agent said.

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 Call

type Call struct {
	Tier turns.Tier
	// Home is the agent's configuration directory, "" for its default.
	Home   string
	Prompt string
}

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.

func (Intakes) Changed

func (a Intakes) Changed(u unit.Unit) (<-chan struct{}, func())

func (Intakes) Peek

func (a Intakes) Peek(ctx context.Context, u unit.Unit, first bool) (intake.Readiness, error)

Peek is Ready without starting a brief or writing.

func (Intakes) Ready

func (a Intakes) Ready(ctx context.Context, u unit.Unit, first bool) (intake.Readiness, error)

func (Intakes) Unwant

func (a Intakes) Unwant(ctx context.Context, u unit.Unit) error

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func New

func New(d Deps) *Queue

func (*Queue) Attempt

func (q *Queue) Attempt(ctx context.Context, ref github.Ref) (int, error)

Attempt is the attempt a first turn of ref waits on, as Ready counts it.

func (*Queue) AttemptOf

func (q *Queue) AttemptOf(pr dinv.PR, rec dinv.BriefRecord) int

AttemptOf is Attempt with the pull request and its brief record already read.

func (*Queue) Breaker

func (q *Queue) Breaker() (open bool, since time.Time, lastErr string, next time.Time)

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

func (q *Queue) Changed(ref github.Ref) (<-chan struct{}, func())

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

func (q *Queue) Forget(ctx context.Context, ref github.Ref) error

Forget drops the brief in use and any give-up, so the next run makes it again; every run stays.

func (*Queue) Interrupted

func (q *Queue) Interrupted(ctx context.Context) error

Interrupted ends the runs a daemon that stopped mid-call left running.

func (*Queue) Next

func (q *Queue) Next(states []inventory.BriefState, now time.Time) (next time.Time, ok bool)

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

func (q *Queue) Peek(ctx context.Context, ref github.Ref, first bool) (Readiness, error)

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

func (q *Queue) Ready(ctx context.Context, ref github.Ref, first bool) (Readiness, error)

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

func (q *Queue) RefreshIfStale(ctx context.Context, pr dinv.PR) error

RefreshIfStale starts one refresh of pr's brief when it is stale and due; View alone never starts a run.

func (*Queue) Run

func (q *Queue) Run(ctx context.Context) (string, error)

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

func (q *Queue) Start(ctx context.Context)

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

func (q *Queue) Status(ctx context.Context) (Status, error)

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

func (q *Queue) Touched(refs []pr.Ref)

Touched wakes the scheduler for pull requests whose inputs changed; any number of calls before it scans make one scan.

func (*Queue) Unwant

func (q *Queue) Unwant(ctx context.Context, ref github.Ref) error

Unwant drops the pull request's want of a brief, once no turn waits on it.

func (*Queue) Views

func (q *Queue) Views(ctx context.Context, prs ...dinv.PR) (map[github.Ref]*View, error)

Views are what the detail panel shows for each of prs, by pull request.

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 Result

type Result struct {
	Brief    Brief
	Model    string
	CostUSD  *float64
	Duration time.Duration
	Tokens   *usage.Tokens
	// DroppedTags are the key:value spellings normalization refused.
	DroppedTags []string
}

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

type Source struct{ GitHub *github.Client }

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.

func (Source) Diff

func (s Source) Diff(ctx context.Context, ref github.Ref, limit int) (string, bool, error)

Diff is ref's diff, at most limit bytes ending on a rune boundary, and whether it was cut.

func (Source) Facts

func (s Source) Facts(ctx context.Context, ref github.Ref) (Input, error)

type Status

type Status struct {
	Ready     int    `json:"ready"`
	Pending   int    `json:"pending"`
	Failed    int    `json:"failed"`
	LastError string `json:"last_error,omitempty"`
	// PausedUntil is the breaker's next trial while it is open.
	PausedUntil time.Time `json:"paused_until,omitzero"`
}

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.

type View

type View struct {
	State string    `json:"state"`
	Brief *Brief    `json:"brief,omitempty"`
	Model string    `json:"model,omitempty"`
	At    time.Time `json:"at,omitzero"`
	Error string    `json:"error,omitempty"`
	// Stale marks a brief that is due again: the pull request moved on.
	Stale bool `json:"stale"`
}

Jump to

Keyboard shortcuts

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