turn

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 33 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 turn renders what an agent reads for one turn of the loop: the context of the turn, its instructions and the prompt that points to them.

Index

Constants

This section is empty.

Variables

View Source
var ProbeTitle = brand.Name + " probe"

ProbeTitle is the title of a probe's pull request, which exists nowhere.

Functions

func Base

func Base() (*template.Template, error)

Base is the set every intent's instructions are parsed on: the bundled partials and the template functions, with missingkey=error. The loader parses a profile's own partials over it.

func Bundled

func Bundled() (*intentload.Loaded, error)

Bundled is the profile the release ships, the bundled layer and the bundled plugins' layers, loaded once; callers never change it.

func BundledFS

func BundledFS() fs.FS

BundledFS is the bundled profile, with intents/ at its root.

func CheckTemplate

func CheckTemplate(d dintent.Def, t *template.Template) []intentload.Problem

CheckTemplate renders an intent's instructions and headlines against sample turns: every declared input set and every one zero, each with and without a resume. Each failure is placed at the template's line.

func FactText

func FactText(v any) string

FactText is a fact value as the why shows it.

func NewCache

func NewCache(layers func() []profile.Layer, opts intentload.CacheOptions) (*intentload.Cache, error)

NewCache is the registry cache over the bundled intents and those of layers. The caches whose layers are all embedded share one registry.

func NewShared added in v0.4.0

func NewShared() (*intentload.Shared, error)

NewShared is a registry over the bundled intents for the caches it makes, apart from the one NewCache and Bundled share.

func PayloadFacts

func PayloadFacts(p Payload) expr.Facts

PayloadFacts are p's provider facts as a predicate reads them.

func Prompt

func Prompt(c Context, id string) string

Prompt is the one line typed into the agent's session: the turn in words, and the command that prints its instructions.

func Trimmed

func Trimmed(c Context) []string

Trimmed are the blocks the turn's guides left out to stay within the judgment limit: the main guide's, then each also_profile guide's under its prefix.

func WhySection

func WhySection(text string) string

WhySection is the why section of rendered instructions, from its heading to the next one; empty when the instructions carry none.

Types

type Brief

type Brief struct {
	Goal, Context, Kind, Size, Risk, RiskWhy string
	// Tags are key:value; Files are the changed paths the brief read.
	OpenQuestions, Tags, Files []string
	// HeadMoved says the pull request got new commits since the brief was
	// written; OlderFormat, that the loop's brief format changed since.
	HeadMoved, OlderFormat bool
	Run                    int64
	// Extra are the brief intent's extra fields, by name.
	Extra map[string]any
}

Brief is the stored preview of a pull request a turn reads.

type Builder

type Builder struct {
	Guides GuideReader
	// Facts reads the stored facts; nil reads nothing.
	Facts FactsReader
	// Intents is the registry the turn's intent comes from.
	Intents func() *intentload.Loaded
	// Viewer is the GitHub login of the user; nil leaves pr.mine false.
	Viewer func(context.Context) (string, error)
	// Config is the configuration for the turn's pull request.
	Config  config.Config
	Command string
	// ManagerBinary is the workspace manager's executable, which a probe never runs; "" for none.
	ManagerBinary string
	// Payloads read each provider's payload.
	Payloads map[unit.ProviderID]PayloadReader
	// Items nil renders no items.
	Items ItemsReader
	// Dossiers nil renders no dossier; a dry run reads none.
	Dossiers DossierReader
}

func (Builder) Build

func (b Builder) Build(ctx context.Context, r Request) (Context, error)

type Contents

type Contents interface {
	Contents() string
}

Contents is a payload that brings its unit's content as text, such as a Slack thread's messages; the instructions quote it as data.

type Context

type Context struct {
	Intent  Intent
	Trigger Trigger
	Planned Planned
	Plain   bool
	Owned   bool
	// NeedsTakeOver, Round, Headline and Records are
	// filled by Complete from the intent's manifest.
	NeedsTakeOver      bool
	Queued             bool
	Guidance           string
	Local              string
	Inputs             map[string]any
	Facts              TurnFacts
	Def                dintent.Def
	Round              string
	Headline           string
	Records            bool
	AutomatedReviewers []string
	Guide              profile.Guide
	// Guides are the composed guides by profile: the main one and each also_profile one that applies.
	Guides        map[string]profile.Guide
	Brief         *Brief
	BriefMissing  string
	Agent         string
	Command       string
	ManagerBinary string
	History       []instructions.PastTurn
	Resume        *instructions.Resume
	// Why is nil for a turn started by hand.
	Why *Why
	// Unit, Payload, Wording and Items are the turn's unit as its provider hands it.
	Unit    unit.Unit
	Payload Payload
	Wording Wording
	Items   []instructions.OpenItem // the unit's open items, filled through Builder.Items
	// Dossier is the unit's dossier, nil when it has none or the turn names none.
	Dossier *Dossier
	// WithoutProjectSettings says the session runs without the checkout's
	// own agent settings, so its instruction files are not in context.
	WithoutProjectSettings bool
}

func Complete

func Complete(c Context, l *intentload.Loaded) (Context, error)

Complete fills what the intent's manifest decides about the turn: its definition, its inputs normalized and zero-filled, NeedsTakeOver, Round, Headline and Records. It is idempotent.

func (Context) Automated

func (c Context) Automated() bool

func (Context) PR

func (c Context) PR() *PR

PR is the github payload, nil on any other unit: the payload itself, or the data of a plugin whose manifest names its payload root PR.

type DataPayload added in v0.3.0

type DataPayload interface {
	Data() json.RawMessage
}

DataPayload is a payload that carries its plugin's data, which the templates read under the payload root the plugin's manifest names.

type Dossier

type Dossier struct {
	Path string
	// Granted says the session was launched with the dossier in its policy.
	Granted bool
	// Merged are the paths of the dossiers of the tasks merged into the unit's task, which the session reads.
	Merged []string
}

Dossier is a unit's dossier as a session turn reaches it.

type DossierReader

type DossierReader interface {
	Dossier(ctx context.Context, u unit.Unit) (Dossier, bool, error)
}

DossierReader opens a unit's dossier for a session turn.

type FactsReader

type FactsReader interface {
	Facts(ctx context.Context, u unit.Unit) (Stored, error)
}

FactsReader reads what the loop keeps about a unit; a unit with no brief and no teams reads the zero Stored.

type FailingCheck added in v0.2.0

type FailingCheck struct {
	Name, Summary, URL string
	Handled            bool
}

FailingCheck is a check that failed on the head; Summary and URL are the CI's own text.

type GuideReader

type GuideReader interface {
	Guide(kind profile.Kind, f profile.Facts) (profile.Guide, error)
}

GuideReader composes the guide a turn of kind reads for a pull request with facts f.

type Intent

type Intent string

type ItemsReader

type ItemsReader interface {
	OpenItems(ctx context.Context, u unit.Unit) ([]instructions.OpenItem, error)
}

ItemsReader lists a unit's open items for its instructions; internal/cli/turnitems.go implements it.

type PR

type PR struct {
	URL, Owner, Repo string
	Number           int
	Title, Author    string
	State            string
	// Association is GitHub's authorAssociation, such as FIRST_TIME_CONTRIBUTOR.
	Association     string
	Head, Base      string
	Labels          []string
	CrossRepository bool
	// Visibility is the repository's: public, private or internal; empty
	// when not read.
	Visibility string
	Prior      *PriorReview
	// ReviewRequested says your review is requested again.
	ReviewRequested bool
	// LastReviewVerdict is the state of your newest review, comments included.
	LastReviewVerdict string
	// Address is why an address round runs now; nil on any other turn.
	Address *RoundReason
}

func (PR) Anchored added in v0.3.0

func (p PR) Anchored(v *RecordedVerdict) *PR

Anchored is p with its prior review anchored to the head the loop's record v covered, when the review is no newer than the record.

func (*PR) Arg

func (p *PR) Arg() string

func (*PR) Fact

func (p *PR) Fact(name string) (any, bool)

func (PR) Slug

func (p PR) Slug() string

func (*PR) Unit

func (p *PR) Unit() unit.Unit

func (*PR) Wording

func (p *PR) Wording() Wording

type Payload

type Payload interface {
	Unit() unit.Unit
	// Arg is how the instructions command names the unit: a PR URL for github, "<provider>:<key>" otherwise.
	Arg() string
	Wording() Wording
	// Fact resolves a provider-namespaced predicate fact ("pr.author"); ok false for a name it does not own.
	Fact(name string) (v any, ok bool)
}

Payload is a unit as its provider hands it to a turn's instructions.

type PayloadCompleter added in v0.3.0

type PayloadCompleter interface {
	CompletePayload(r Request, p Payload) (Payload, error)
	SyntheticPayload(u unit.Unit, probe bool) (Payload, error)
}

PayloadCompleter is a PayloadReader that completes a payload the caller handed the turn, and names a unit without reading it for an intent whose context is synthetic, such as a probe.

type PayloadReader

type PayloadReader interface {
	Payload(ctx context.Context, r Request) (Payload, error)
}

PayloadReader is a provider's turn payload: a source plugin's Planner.Payload as the turn reads it.

type Planned

type Planned int

Planned is the review round the sweep decided to send. A round asked for by hand is Unplanned: your reviews on GitHub make it a follow-up or not.

const (
	Unplanned Planned = iota
	PlannedFirst
	PlannedFollowUp
)

func (Planned) String

func (p Planned) String() string

type PriorReview

type PriorReview struct {
	Verdict, Head, Endorsed string
	At                      time.Time
}

PriorReview is your latest review of a pull request: the head it covered, when, and the latest verdict that was not a comment, "" when all were. Endorsed is the endorsement of the turn that published the last verdict, "" when no turn of the loop's did.

type RecordedVerdict

type RecordedVerdict struct {
	Head, Endorsed string
	At             time.Time
}

RecordedVerdict is the newest verdict a turn of the loop's published: the head its record covered, its endorsement and when it was recorded.

type Rendered

type Rendered struct {
	ID   string
	Text string
	// Sources are the guide files the text was rendered from; they never
	// reach the agent.
	Sources []string
	// Records says the instructions end the turn with a record.
	Records bool
}

func Render

func Render(c Context, l *intentload.Loaded, devDir string) (Rendered, error)

Render writes the instructions of a completed turn. devDir, when set, is a profile directory whose partials/ and intents/<name>/instructions.md.tmpl of bundled intents replace the bundled ones.

type Request

type Request struct {
	Intent  Intent
	Trigger Trigger
	Planned Planned
	Unit    unit.Unit
	// LastVerdict anchors PR.Prior to the head the loop's record covered, which
	// GitHub's review commit drifts from after later pushes.
	LastVerdict *RecordedVerdict
	Guidance    string
	Local       string // work in the checkout not on the pull request
	Queued      bool   // the prompt waits behind the agent's current turn
	Agent       string
	// Plain is profile try's dry run: the turn publishes and records nothing.
	Plain bool
	// Owned says the caller checked the pull request is the user's to develop.
	Owned bool
	// Inputs are the intent's declared inputs the caller set, by name.
	Inputs map[string]any
	// Payload nil makes Build read it through Builder.Payloads.
	Payload Payload

	History []instructions.PastTurn
	// Resume makes this a resume turn of one whose session is gone.
	Resume *instructions.Resume
	// BriefMissing says why the turn goes without a brief, when it does.
	BriefMissing string
	// Why is the workflow that started the turn; nil for a turn started by hand.
	Why *workflow.Why
	// Items and Task are the unit's item ids and the task the turn was asked about.
	Items []string
	Task  string
}

Request is what a caller knows when it starts a turn; Build completes it into a Context.

type RoundConflict added in v0.2.0

type RoundConflict struct {
	Base    string
	Handled bool
}

RoundConflict is the head's conflict with Base, as GitHub reports it.

type RoundReason added in v0.2.0

type RoundReason struct {
	Reviewers []RoundReviewer
	Checks    []FailingCheck
	Conflict  *RoundConflict
}

RoundReason is what an address round answers: the reviewers, the failing checks and a conflict with the base. Handled marks what an earlier round already covered.

func (*RoundReason) CheckNames added in v0.2.0

func (r *RoundReason) CheckNames() []string

func (*RoundReason) ReviewerLogins added in v0.2.0

func (r *RoundReason) ReviewerLogins() []string

type RoundReviewer added in v0.2.0

type RoundReviewer struct {
	Login   string
	Handled bool
}

type Scenario

type Scenario struct {
	Name    string
	Context Context
	// Expect is the judge's brief: what the agent must know after reading.
	Expect        string
	Must, MustNot []string
	// MaxWords bounds the text before "## Brief", or "## Judgment" without one.
	MaxWords int
}

Scenario is a turn the eval renders: what its text must and must not carry, and the brief the judge reads.

func Scenarios

func Scenarios() []Scenario

Scenarios are the eval's turns, each completed against the bundled intents.

type Stored

type Stored struct {
	// Brief is nil when none is stored.
	Brief *Brief
	// Teams are the teams a review was requested through, as <org>-<slug>.
	Teams []string
}

Stored is what the loop keeps about a unit beyond its provider's read.

type Trigger

type Trigger int
const (
	ByHand Trigger = iota
	Automated
)

func (Trigger) String

func (t Trigger) String() string

type TurnFacts

type TurnFacts struct {
	Mine, CrossRepository                                                             bool
	LastReviewVerdict                                                                 string
	AddressReviews, AddressChecks, FollowupsWithoutWorkspace, AddressWithoutWorkspace bool
	// RequestedTeams are the teams a review was requested through, as <org>-<slug>.
	RequestedTeams []string
}

TurnFacts are the facts of a turn Build reads besides the request.

type Why

type Why struct {
	Workflow, Trigger, Event, EventData string
	Matched                             []WhyFact
}

Why is what made a workflow start the turn, as the instructions render it.

type WhyFact

type WhyFact struct{ Name, Value string }

WhyFact is a fact the workflow's condition read, with its value as text.

type Wording

type Wording struct {
	Noun  string // "pull request", "Slack thread"
	This  string // "this pull request"
	Ref   string // "acme/api#7", "#eng thread 1700000000.123456"
	Short string // headline form, as {{.PR.Slug}} today
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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