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 AttemptKey(version string, at At) string
- func Due(pr dinv.PR, rec dinv.BriefRecord, ok bool, version string, now time.Time, ...) bool
- func Facts(b *Brief, c Composed) workflow.Facts
- func InputSHA(head, settings string, in Input) string
- func Prompt(taxonomy, vocabulary string, in Input) string
- func Version(taxonomy string) string
- type AskRunner
- type At
- type Brief
- type BriefSource
- type Call
- type Composed
- func (c Composed) DecodeFields(answer []byte, names []string) (map[string]any, error)
- func (c Composed) FieldVersions() map[string]string
- func (c Composed) FieldsJSON(names []string) string
- func (c Composed) JSON() string
- func (c Composed) Missing(b Brief) []string
- func (c Composed) Validate(answer []byte) (Brief, error)
- func (c Composed) WithFields(b Brief, values map[string]any) Brief
- type Deps
- type GitHubSource
- type Input
- type Intakes
- func (a Intakes) Changed(_ context.Context, u unit.Unit) (<-chan struct{}, func())
- func (a Intakes) Peek(ctx context.Context, u unit.Unit, first bool, need []string) (intake.Readiness, error)
- func (a Intakes) Ready(ctx context.Context, u unit.Unit, first bool, need []string) (intake.Readiness, error)
- func (a Intakes) Unwant(ctx context.Context, u unit.Unit) error
- type Intent
- type OnDemand
- type PRReader
- type Projection
- 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(u unit.Unit) (<-chan struct{}, func())
- func (q *Queue) Due() <-chan struct{}
- func (q *Queue) Fill(ctx context.Context, u unit.Unit, need []string) (bool, error)
- 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) Noted(u unit.Unit)
- func (q *Queue) Peek(ctx context.Context, u unit.Unit, first bool, need []string) (Readiness, error)
- func (q *Queue) Ready(ctx context.Context, u unit.Unit, first bool, need []string) (Readiness, error)
- func (q *Queue) RefreshIfStale(ctx context.Context, pr dinv.PR) error
- func (q *Queue) Register(p unit.ProviderID, s BriefSource)
- 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, u unit.Unit) error
- func (q *Queue) Views(ctx context.Context, prs ...dinv.PR) (map[github.Ref]*View, error)
- type Readiness
- type ReadyState
- type Records
- type Result
- type RunStore
- type Status
- type Store
- type Summary
- type UnitInput
- type View
- type Written
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 ( PromptFile = "prompts/brief.md" FieldsPromptFile = "prompts/brief-fields.md" TaxonomyFile = "prompts/brief-taxonomy.md" )
PromptFile and TaxonomyFile are the bundled profile's brief prompt and taxonomy, relative to the profile's root.
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" // TriggerFields is a run that fills a brief's missing extra fields, // reusing its core. TriggerFields = "fields" )
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 DemandTimeout = 2 * time.Minute
DemandTimeout bounds a first turn's wait for an OnDemand source's brief: the Slack extraction runs every 30 seconds and its call takes as long.
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 = bundled(TaxonomyFile)
DefaultTaxonomy is the bundled profile's taxonomy.
var ErrExtra = errors.New("the brief's extra fields do not fit their schema")
ErrExtra is a model answer whose core brief fits and whose extra fields do not: the core brief is kept and the fields stay missing.
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 AttemptKey ¶ added in v0.3.0
AttemptKey names an attempt at version on a unit at at, as attempt_of stores it, so a failure counts against that attempt only.
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 Facts ¶ added in v0.2.0
Facts are the brief.* facts of b under c, the brief intent's composed schema: empty values, and every extra field missing, when the unit has no brief. Extra fields b holds at an older version still read as their value and are listed in brief.missing.
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 At ¶ added in v0.2.0
type At struct {
Revision string
Parts json.RawMessage
Attempt string
}
At is what a unit is at: its revision in the provider's own format, as brief_runs.revision stores it, the parts of its input a staleness rule reads, as brief_runs.input stores them, and what an attempt at it is made from, in the provider's own format.
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"`
// Extra are the brief intent's extra fields, by name, and the version
// of each field the brief holds.
Extra map[string]any `json:"extra,omitempty"`
ExtraVersions map[string]string `json:"extra_versions,omitempty"`
}
type BriefSource ¶ added in v0.2.0
type BriefSource interface {
// Input reads what a brief of u reads now.
Input(ctx context.Context, u unit.Unit) (UnitInput, error)
// Revision is what u is at now, read without the input.
Revision(ctx context.Context, u unit.Unit) (At, error)
// Describe is in, one line, as the prompt's header names it.
Describe(in UnitInput) string
// Stale says whether the brief w holds of a unit now at cur is due
// again at now, version being the brief's current version.
Stale(w Written, cur At, version string, now time.Time) bool
}
BriefSource is what the brief queue asks a provider about its units, the calls of a source plugin's Briefer. A provider without one answers "without" to the intakes of its units.
type Call ¶
type Call struct {
Tier turns.Tier
// Home is the agent's configuration directory, "" for its default.
Home string
Prompt string
// Schema is what the answer is asked for and validated against; the
// zero Composed is the core schema.
Schema Composed
// Fields, when set, asks only these extra fields of a brief that has
// its core: the missing-fields call.
Fields []string
}
type Composed ¶ added in v0.2.0
type Composed struct {
// Core is the core schema's JSON.
Core string
// Extra is the brief intent's flat extra schema; nil when it declares
// none, and then JSON is Core byte for byte.
Extra *jsonschema.Schema
// contains filtered or unexported fields
}
Composed is the schema a brief call sends and Go validates the answer against: the core schema Go owns (goal, context, kind, size, risk, risk_why, open_questions, tags and the provider's facets) plus {"extra": <the brief intent's schema.json>}. The zero Composed is the core schema alone.
func Compose ¶ added in v0.2.0
Compose is the composed schema of the core schema and extra, the brief intent's schema.json; a nil extra adds nothing. extra must be a flat object schema: a nested object or a keyword outside the subset fails, naming the field.
func ComposeExtra ¶ added in v0.2.0
func ComposeExtra(core string, props []jsonschema.Property) (Composed, error)
ComposeExtra is Compose with the extra schema made of a brief intent's properties, every one required: the brief intent's Def.Extra.
func (Composed) DecodeFields ¶ added in v0.2.0
DecodeFields validates a missing-fields answer asking for names.
func (Composed) FieldVersions ¶ added in v0.2.0
FieldVersions are the versions of c's extra fields, by name: a hash of each property's schema.
func (Composed) FieldsJSON ¶ added in v0.2.0
FieldsJSON is the schema of a missing-fields answer, {"extra": {...}} holding names alone, every one required.
func (Composed) Missing ¶ added in v0.2.0
Missing are the extra fields b lacks at their current version, by name.
type Deps ¶
type Deps struct {
Store Store
// PRs are the pull requests the GitHub plugin last reported; nil knows
// none.
PRs PRReader
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
// agent to ask: their turns start without a brief, Runner may be nil
// and the queue is never started. On-demand units are briefed all the
// same.
Unavailable string
// 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
// DemandTimeout bounds a first turn's wait for an OnDemand source's
// brief; zero is the package's.
DemandTimeout 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)
// Intent is the brief intent of a provider's units as the profile
// resolves it now; nil is the bundled one.
Intent func(p unit.ProviderID) Intent
// Records projects a pull request's brief record onto the tasks holding
// it; nil projects none.
Records *Records
// Sources are the providers' BriefSources by provider. Pull requests
// default to GitHubSource over Store and Source; a GitHub source set
// here keeps Retry. A source that is also an OnDemand briefs its units
// on a first turn's demand.
Sources map[unit.ProviderID]BriefSource
}
type GitHubSource ¶ added in v0.2.0
type GitHubSource struct {
Store PRReader
Source interface {
Facts(ctx context.Context, ref github.Ref) (Input, error)
Diff(ctx context.Context, ref github.Ref, limit int) (string, bool, error)
}
MaxDiffBytes int
// Retry is the first wait after a failed attempt, the queue's Deps.Retry.
Retry time.Duration
}
GitHubSource is the BriefSource of pull requests: the revision is the head and the description's edit time, the parts the changed files; its staleness and attempt rules are the queue's.
func (GitHubSource) Describe ¶ added in v0.2.0
func (g GitHubSource) Describe(in UnitInput) string
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) Peek ¶
func (a Intakes) Peek(ctx context.Context, u unit.Unit, first bool, need []string) (intake.Readiness, error)
Peek is Ready without starting a brief or writing.
type Intent ¶ added in v0.2.0
Intent is what the brief intent sets of a brief: the composed schema, the zero Composed being the core alone, and the prompt and the missing-fields prompt, empty for the bundled ones.
type OnDemand ¶ added in v0.2.0
type OnDemand interface {
// Want asks for u's brief now; false when no brief of u is coming,
// such as when nothing of it is left to read.
Want(ctx context.Context, u unit.Unit) (bool, error)
}
OnDemand is a BriefSource whose briefs another job writes, such as the Slack extraction, which a first turn asks for its unit's brief. The job tells the queue of each brief it writes through Noted.
type Projection ¶ added in v0.3.0
type Projection struct {
Projects map[string]string
Parse func(prop, text string, w task.Writer) (task.Value, bool)
}
Projection is how a brief record sets the properties of its task, as records.toml declares it: Projects are the fields that set a property, by field; Parse is a property's value from a field's text, false when w may not write the property or the text is no value of it.
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 u after the call, or by another job noting u's brief; 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) Fill ¶ added in v0.2.0
Fill fills the extra fields u's brief lacks, those of need when need is not empty, without briefing its core again; see fillPR. Only pull requests' briefs are filled this way, and only by a queue that can brief: another provider's job writes its fields at its next pass.
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) Noted ¶ added in v0.2.0
Noted wakes the Changed of u once another job wrote its brief.
func (*Queue) Peek ¶
func (q *Queue) Peek(ctx context.Context, u unit.Unit, first bool, need []string) (Readiness, error)
Peek is Ready's answer without starting a brief, waiting or writing.
func (*Queue) Ready ¶
func (q *Queue) Ready(ctx context.Context, u unit.Unit, first bool, need []string) (Readiness, error)
Ready answers for a turn of u. A pull request is briefed by the queue: a first turn waits for a brief at the current version, a later one takes the brief there is. need are the extra fields the turn's intent needs: a first turn also waits until a call fills the missing ones, once, and a later one starts that call. A unit of another provider takes its brief in use; a first turn without one asks its OnDemand source and waits, at most DemandTimeout, while the source says a brief is coming.
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) Register ¶ added in v0.2.0
func (q *Queue) Register(p unit.ProviderID, s BriefSource)
Register adds p's BriefSource.
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 Records ¶ added in v0.3.0
type Records struct {
// Holders are the tasks that hold a unit.
Holders interface {
TasksHolding(ctx context.Context, u unit.Unit) ([]task.ID, error)
}
Props interface {
SetProp(ctx context.Context, id task.ID, name string, v task.Value, w task.Writer) error
}
// Projection is the brief record kind's as the profile declares it now.
Projection func() Projection
}
Records projects brief records onto tasks.
func (*Records) Project ¶ added in v0.3.0
Project sets, on each task of ids, the properties data sets as w wrote it; a task gone since is skipped.
func (*Records) ProjectHeld ¶ added in v0.3.0
ProjectHeld sets, on every task holding u, the properties u's brief record data sets, as w wrote it: a pull request task's brief is its pull request's.
func (*Records) ProjectUnheld ¶ added in v0.3.0
ProjectUnheld sets, on every task holding u that holds none of the properties u's brief record data sets, those properties as w wrote them: a task that starts holding a briefed pull request takes its brief's properties once, and a value already there, a person's included, stays.
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
// Fields are a missing-fields call's values, by name.
Fields map[string]any
// ExtraErr is why the extra fields of an otherwise fitting brief were
// refused; the brief holds none of them.
ExtraErr error
}
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 Store ¶
type Store interface {
BriefStates(ctx context.Context) ([]inventory.BriefState, 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)
UnitBrief(ctx context.Context, u unit.Unit) (inventory.UnitBrief, bool, 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"`
// Extra are the brief intent's extra fields the brief holds, by name.
Extra map[string]any `json:"extra,omitempty"`
}
Summary is what a row of the list shows of a brief.
type UnitInput ¶ added in v0.2.0
type UnitInput struct {
// Text is the unit's own text the prompt's data block holds.
Text string
// Bytes is the whole input's size, 0 when unknown; Cut says Text is cut.
Bytes int
Cut bool
// Parts are the provider's parts as a JSON object, such as GitHub's
// changed files.
Parts json.RawMessage
}
UnitInput is what a brief of a unit reads: the text the prompt carries and the provider's own parts, which brief_runs.input stores.
type Written ¶ added in v0.2.0
type Written struct {
// At is what the unit was at when the brief in use was made.
At At
Version string
// Error is the last attempt's error, empty when it went ok.
Error string
Failures int
AttemptedAt time.Time
// AttemptOf is AttemptKey of the last attempt.
AttemptOf string
}
Written is what a stored brief was made from and how its last attempt went, as brief_runs and unit_briefs keep it.