headless

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 23 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 headless runs a turn as one restricted agent call, with no session.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout bounds a headless call when Service.Timeout is zero.

View Source
const MaxDrafts = 3

MaxDrafts is how many drafts one headless answer may propose.

View Source
const WrapperFile = "prompts/headless.md.tmpl"

WrapperFile is the profile file of the headless call's prompt.

Variables

View Source
var (
	ErrBusy        = turns.ErrHeadlessBusy
	ErrOverCap     = turns.ErrOverCap
	ErrNotHeadless = errors.New("the turn is not headless")
)

Functions

func Markers added in v0.4.0

func Markers(what string) (begin, end, nonce string)

Markers are one call's markers around the untrusted data it quotes, named what, and their fresh code: a marker with any other code is part of the data.

func Schema

func Schema() string

Schema is the answer schema of a headless call.

Types

type Builder

type Builder interface {
	Instructions(ctx context.Context, u unit.Unit, intent turn.Intent, items []string) (string, error)
}

Builder renders a unit's instructions for an intent; implemented in internal/cli over internal/turn.

type Caps

type Caps struct {
	PerCallUSD, PerDayUSD float64
	// Tier is the model tier of the calls; "" is balanced.
	Tier turns.Tier
}

type Placer

type Placer interface {
	Checkout(ctx context.Context, u unit.Unit, item string) (dir string, ok bool, err error)
}

Placer resolves a placement to an existing directory, implemented in internal/cli: an absolute Checkout as is, "main" the repo's main checkout path; "" (a new worktree) and ErrUnplaced give ok false: a headless turn never creates a worktree.

type Readier

type Readier interface {
	Ready(ctx context.Context, a turns.Ask) error
}

Readier is an Asker that tells, spawning nothing, whether a call can run.

type Request

type Request struct {
	Unit     unit.Unit
	Items    []string // item ids acted on
	Task     string
	Intent   turn.Intent // "" is the Service's Default
	Guidance string
	Trigger  turn.Trigger
	Workflow string // "" by hand
	// ResumeOf is the headless turn whose question this run answers, 0 none.
	ResumeOf int64
}

type Result

type Result struct {
	Seq     int64         // the turn
	Record  record.Record // as stored
	Drafts  []draft.Draft // proposed, origin turn Seq
	Ops     int           // ledger ops applied
	CostUSD *float64
}

type Service

type Service struct {
	Turns *turns.Service // records the turn; its Items ledger applies the record's ops with provenance turn
	Build Builder
	Place Placer
	Asker turns.Asker
	// Ledger reads the unit's items, which a draft's items must name; nil checks none.
	Ledger  items.Applier
	Outbox  *outbox.Service
	Intents func(name turn.Intent) (intent.Def, bool)
	// Default is the intent a request that names none runs on units of p.
	Default func(p unit.ProviderID) (intent.Def, bool)
	Caps    Caps // from config "headless"
	// Context is the daemon's lifetime: a stop cancels the calls Start runs; nil is context.Background.
	Context context.Context
	Timeout time.Duration                                             // a call's limit; 0 is DefaultTimeout
	Spent   func(ctx context.Context, day time.Time) (float64, error) // turn_usage of headless turns that day
	Dossier func(ctx context.Context, u unit.Unit) (path string, ok bool)
	// Logged writes the answer's log to the unit's dossier once the turn's record is stored; nil writes none.
	Logged func(ctx context.Context, u unit.Unit, seq int64, log string)
	Clock  port.Clock
	// Go runs a started call in the background, for Start and Again; nil runs it on a new goroutine.
	Go  func(run func())
	Log func(format string, args ...any)
	// Wrapper is the profile's prompt around the unit's instructions, read at each call.
	Wrapper func() (Wrapper, error)
	// contains filtered or unexported fields
}

func (*Service) Again

func (s *Service) Again(ctx context.Context, q turn.Turn, said string) (turns.AnswerResult, error)

Again runs q's intent on q's unit, items and task (kept in q.Inputs) with said as Guidance, q.Trigger and q.Workflow; ErrNotHeadless when q.Mode is not headless. The route is Resumed.

func (*Service) Run

func (s *Service) Run(ctx context.Context, r Request) (Result, error)

Run stores the turn, calls the agent and records its answer; it passes turns.ErrNoRestricted through.

func (*Service) Start

func (s *Service) Start(ctx context.Context, r Request) (int64, error)

Start stores the turn and runs its call in the background; the turn's seq is known once it returns.

type Wrapper added in v0.2.0

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

Wrapper is the headless call's prompt around the unit's instructions, a template defining "before", the text ahead of the unit data's markers, and "after", the text between the end marker and the answer schema. The markers, the instructions between them and the schema are written in Go.

func ParseWrapper added in v0.2.0

func ParseWrapper(src string) (Wrapper, error)

ParseWrapper reads a wrapper template; it must define before and after.

func (Wrapper) Prompt added in v0.2.0

func (w Wrapper) Prompt(r Request, checkout, dossier, instructions string) (string, error)

Prompt is the headless call's prompt: the wrapper's before, the unit's instructions between this call's markers, the wrapper's after, then the answer schema, last so nothing quoted from the unit follows it.

type WrapperData added in v0.2.0

type WrapperData struct {
	Name, Unit, Checkout, Dossier string
	// Items is the items acted on, each in backquotes, comma-separated.
	Items string
	// Guidance is the user's guidance, each line indented four spaces.
	Guidance string
	// Begin and End are the unit data's markers; Nonce is their code.
	Begin, End, Nonce string
	MaxDrafts         int
}

WrapperData is what the wrapper's templates read.

Jump to

Keyboard shortcuts

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