harness

package
v0.2.59 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 71 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

Index

Constants

View Source
const (
	ChatResponseAssistantMessage    = "assistant_message"
	ChatResponseAssistantCommentary = "assistant_commentary"
	ChatResponseReasoningSummary    = "reasoning_summary"
)
View Source
const (
	AllowBackgroundSubject = "allow_background"
)
View Source
const (
	MaxCodeModeCalls = 200
)
View Source
const (
	TurnBoundRefused = "" /* 288-byte string literal not displayed */
)

Variables

View Source
var AgentFrontmatterPattern = regexp.MustCompile(`\A---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|\z)`)
View Source
var ErrBackgroundKilled = errors.New("background job killed")
View Source
var ErrShutdown = errors.New("shutdown")

Functions

func BashPermissionSubjects

func BashPermissionSubjects(command string) []string

func CallKey

func CallKey(turnID, callID string) string

func CheckNestedPermission

func CheckNestedPermission(ctx context.Context, toolName, permission, subject string, args map[string]any) error

func CheckNestedToolCall

func CheckNestedToolCall(ctx context.Context, toolName string, tool *looperTool, args json.RawMessage) error

func CompactionCheckpointText

func CompactionCheckpointText(compaction *responses.ResponseCompactionItemParam) string

func EasyRoot added in v0.2.20

func EasyRoot(shell *CustomShell, name string) (root *os.Root, rel string, err error)

func GenerateSummary added in v0.2.48

func GenerateSummary(ctx context.Context, resolver ModelResolver, model, effort, transcript string) (string, error)

func GenerateTitle added in v0.2.44

func GenerateTitle(ctx context.Context, resolver ModelResolver, titleModel, request, recent string) (string, error)

func InterpolatePermissions

func InterpolatePermissions(agent *Agent, env map[string]string)

func LoadRetainedFiles added in v0.2.59

func LoadRetainedFiles(root *os.Root, dir, resultID string) ([]*codemode.File, error)

func ParseModelRef added in v0.2.20

func ParseModelRef(ref string) (model, effort string)

func PermissionPrompt added in v0.2.59

func PermissionPrompt(permissions PermissionSet) string

func PromptInputMessage added in v0.2.40

func PromptInputMessage(input *PromptInput) responses.ResponseInputItemUnionParam

func RemapReplayAttribution

func RemapReplayAttribution(ranges []ReplayAttribution, boundaries []int)

func ReplayInputFromParams

func ReplayInputFromParams(items []responses.ResponseInputItemUnionParam) ([]json.RawMessage, error)

func ReplayInputRawKind

func ReplayInputRawKind(raw json.RawMessage) string

func ReviewKey

func ReviewKey(turnID, callID string) string

func ReviewTurn

func ReviewTurn(callKey string) string

func SettleStoppedTrace added in v0.2.59

func SettleStoppedTrace(ctx context.Context, journal Journal, turnID string, trace []json.RawMessage) error

func SweepRetainedResults

func SweepRetainedResults(root *os.Root, dir string)

func TaskResult

func TaskResult(answer string) string

func ToolCallKey

func ToolCallKey(ctx context.Context) string

Types

type Agent

type Agent struct {
	Name             string
	Description      string
	Model            string
	ReasoningEffort  string
	Verbosity        string
	MaxRecursion     *int
	CustomShell      CustomShell
	Space            string
	Prompt           string
	Location         string
	Permission       PermissionSet
	OutputSchema     map[string]any
	ApproverDecision ApproverDecision
	Frontmatter      map[string]any
	FrontmatterNode  *yaml.Node
	FileMode         fs.FileMode
	Mode             AgentMode
	Sticky           AgentSticky

	WorkingDirectory string
	Commands         map[string]string
	SecretsARN       []string
	Subagents        []string
	ApproverModel    string
	ApproverPrompt   string
	Approver         *Agent
	Routines         []AgentRoutine
	TagGroups        [][]string
	DelegatedFrom    []string
	NetworkTargets   []string
	Tools            []string
}

func ToolCallAgent

func ToolCallAgent(ctx context.Context) (Agent, bool)

type AgentLoadConfig added in v0.2.20

type AgentLoadConfig struct {
	MCPFacets         map[string]map[string][]string
	Providers         []string
	DecisionProviders []string
	OpenCodeServers   []string
	Skills            fs.FS
}

type AgentLoadResult

type AgentLoadResult struct {
	Agents Agents
	Errors []error
}

func LoadAgents

func LoadAgents(fsys fs.FS, cfg *AgentLoadConfig) AgentLoadResult

type AgentMaxRecursionError

type AgentMaxRecursionError struct {
	Location string
	Err      error
}

func (*AgentMaxRecursionError) Error

func (e *AgentMaxRecursionError) Error() string

func (*AgentMaxRecursionError) Unwrap

func (e *AgentMaxRecursionError) Unwrap() error

type AgentMode added in v0.2.20

type AgentMode string
const (
	AgentModeAdvanced AgentMode = "advanced"
	AgentModeEasy     AgentMode = "easy"
)

func (AgentMode) Valid added in v0.2.41

func (m AgentMode) Valid() bool

type AgentRoutine added in v0.2.20

type AgentRoutine struct {
	Schedule    string
	Instruction string
}

type AgentSetting added in v0.2.41

type AgentSetting struct {
	Key         string
	Modes       []AgentMode
	Group       string
	Label       string
	Explanation string
	Default     string
	Allowed     string
	Control     AgentSettingControl
	Choices     []string
	Required    bool
	Common      bool
}

func AgentSettings added in v0.2.41

func AgentSettings() []AgentSetting

func AgentSettingsFor added in v0.2.41

func AgentSettingsFor(mode AgentMode) []AgentSetting

type AgentSettingControl added in v0.2.41

type AgentSettingControl string
const (
	AgentSettingText   AgentSettingControl = "text"
	AgentSettingSwitch AgentSettingControl = "switch"
	AgentSettingChoice AgentSettingControl = "choice"
	AgentSettingList   AgentSettingControl = "list"
	AgentSettingModel  AgentSettingControl = "model"
	AgentSettingFile   AgentSettingControl = "file"
)

type AgentSticky added in v0.2.30

type AgentSticky string
const (
	AgentStickyOff    AgentSticky = ""
	AgentStickyUser   AgentSticky = "user"
	AgentStickyGlobal AgentSticky = "global"
	AgentStickySlack  AgentSticky = "slack"
)

type Agents

type Agents struct {
	Items map[string]Agent
}

func (Agents) PrimaryNames

func (a Agents) PrimaryNames() []string

func (Agents) ShadowNames

func (a Agents) ShadowNames(parent string) []string

type ApproverDecision added in v0.2.31

type ApproverDecision struct {
	Model         string  `yaml:"model"`
	MinConfidence float64 `yaml:"minConfidence"`
	Prompt        string  `yaml:"prompt"`
}

type Attachment

type Attachment struct {
	MIME     string `json:"mime"`
	Filename string `json:"filename,omitempty"`
	URL      string `json:"url"`
}

type BackgroundJob

type BackgroundJob struct {
	ID          string
	Kind        BackgroundKind
	Label       string
	Agent       string
	SubagentKey string
	CallID      string
	Detached    bool
}

type BackgroundJobs

type BackgroundJobs interface {
	Enabled() bool
	Run(ctx context.Context, job *BackgroundJob, work BackgroundWork) (BackgroundResult, error)
}

type BackgroundKind

type BackgroundKind string
const (
	BackgroundKindExecute BackgroundKind = "execute"
	BackgroundKindTask    BackgroundKind = "task"
)

type BackgroundResult

type BackgroundResult struct {
	Result ToolResult
	Moved  bool
}

type BackgroundStopError added in v0.2.59

type BackgroundStopError string

func (BackgroundStopError) Error added in v0.2.59

func (e BackgroundStopError) Error() string

func (BackgroundStopError) Unwrap added in v0.2.59

func (BackgroundStopError) Unwrap() error

type BackgroundWork

type BackgroundWork interface {
	RunBackground(ctx context.Context) (ToolResult, error)
	Detach() bool
}

type BashResult

type BashResult struct {
	Output    string
	ErrorCode string
	Success   bool
}

func (BashResult) String

func (r BashResult) String() string

type ChatResponse

type ChatResponse struct {
	Kind string
	Text string
}

type ChildKey

type ChildKey struct {
	Path, Parent, Turn, Call string
}

type ChildSessions

type ChildSessions interface {
	AppendChildEntry(ctx context.Context, key ChildKey, entry *SessionEntry) error
	WriteSubagent(ctx context.Context, write *SubagentWrite) (steered bool, err error)
	AwaitSubagent(ctx context.Context, key, callKey string) (string, ReplayAttribution, error)
}

type CodeModeCall

type CodeModeCall struct {
	Type         string                  `json:"type"`
	ParentCallID string                  `json:"parent_call_id"`
	Key          string                  `json:"key,omitempty"`
	Name         string                  `json:"name,omitempty"`
	Arguments    string                  `json:"arguments,omitempty"`
	Status       codeModeCallStatus      `json:"status,omitempty"`
	Summary      string                  `json:"summary,omitempty"`
	Outcome      permissionReviewOutcome `json:"outcome,omitempty"`
	Reason       string                  `json:"reason,omitempty"`

	CreatedPullRequests   []string `json:"created_pull_requests,omitempty"`
	MentionedPullRequests []string `json:"mentioned_pull_requests,omitempty"`
	// contains filtered or unexported fields
}

func CodeModeCallsFromTrace

func CodeModeCallsFromTrace(traces []json.RawMessage) []CodeModeCall

func (*CodeModeCall) String

func (r *CodeModeCall) String() string

type Config

type Config struct {
	AutoApproverModel         shared.ResponsesModel
	AutoApproverDecisionModel string
	AutoApproverMinConfidence float64
	Deciders                  map[string]Decider
	ExpandPromptShellCommands PromptShellCommandExpansion
	ParallelToolCalls         int
	ShellTempDir              string
	SpillDir                  string
	RetainedResultDir         string
	Observability             ObservabilityConfig
	ChildSessions             ChildSessions
	Journal                   Journal
	BackgroundJobs            BackgroundJobs
	CustomTools               []Tool
	ShellEnv                  map[string]string
	ChildContext              []SessionEntry
	OriginHeader              string
	Sandbox                   sandbox.Runtime
	MCPServers                map[string]mcpclient.ServerConfig
	MCPWorkspace              string
}

type ContinueMode

type ContinueMode string
const (
	ContinueStop    ContinueMode = "stop"
	ContinueSteer   ContinueMode = "steer"
	ContinueEnqueue ContinueMode = "enqueue"
)

type CustomShell

type CustomShell struct {
	Path           string
	Emulated       bool
	Dir            string
	ReadOnly       []string
	Commands       map[string]string
	NetworkTargets []string
	Secrets        map[string]string
	Env            []string
}

type Decider added in v0.2.31

type Decider interface {
	Decide(ctx context.Context, request *DecisionRequest) ([]DecisionAnswer, DecisionUsage, error)
}

type DecisionAnswer added in v0.2.31

type DecisionAnswer struct {
	Name          string
	Type          DecisionQuestionType
	Refused       bool
	Probability   float64
	Choice        string
	Score         float64
	Confidence    float64
	Probabilities map[string]float64
}

type DecisionImage added in v0.2.31

type DecisionImage struct {
	MIME   string
	Base64 string
}

type DecisionOption added in v0.2.31

type DecisionOption struct {
	Value       string
	Description string
}

type DecisionQuestion added in v0.2.31

type DecisionQuestion struct {
	Name         string
	Type         DecisionQuestionType
	Instructions string
	Options      []DecisionOption
}

type DecisionQuestionType added in v0.2.31

type DecisionQuestionType string
const (
	DecisionPredicate DecisionQuestionType = "predicate"
	DecisionChoice    DecisionQuestionType = "choice"
	DecisionScore     DecisionQuestionType = "score"
)

type DecisionRequest added in v0.2.31

type DecisionRequest struct {
	Model        string
	Instructions string
	Input        any
	Images       []DecisionImage
	Questions    []DecisionQuestion
}

type DecisionUsage added in v0.2.31

type DecisionUsage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
}

type InertBackgroundJobs

type InertBackgroundJobs struct{}

func (InertBackgroundJobs) Enabled

func (InertBackgroundJobs) Enabled() bool

func (InertBackgroundJobs) Run

type InertChildSessions

type InertChildSessions struct{}

func (InertChildSessions) AppendChildEntry

func (InertChildSessions) AwaitSubagent

func (InertChildSessions) WriteSubagent

type InertJournal

type InertJournal struct{}

func (InertJournal) CodeModeCalls

func (InertJournal) CodeModeCalls(context.Context, string) ([]json.RawMessage, error)

func (InertJournal) Items

func (InertJournal) Load

func (InertJournal) Load(context.Context, string) (value json.RawMessage, found bool, err error)

func (InertJournal) Save

func (InertJournal) SaveCodeModeCall

func (InertJournal) SaveTrace

func (InertJournal) SaveTurn

type InertSteerDrain

type InertSteerDrain struct{}

func (InertSteerDrain) Drain

type Journal

type Journal interface {
	Load(ctx context.Context, key string) (json.RawMessage, bool, error)
	Save(ctx context.Context, key string, value json.RawMessage) error
	SaveTurn(ctx context.Context, turnID string, step json.RawMessage, lists []TurnItems) error
	Items(ctx context.Context, turnID string, list TurnList) ([]json.RawMessage, error)
	SaveTrace(ctx context.Context, turnID string, trace []json.RawMessage) error
	SaveCodeModeCall(ctx context.Context, turnID, key string, record json.RawMessage) error
	CodeModeCalls(ctx context.Context, turnID string) ([]json.RawMessage, error)
}

type ModelResolver

type ModelResolver interface {
	Resolve(model string) (*openai.Client, ProviderOrigin, error)
}

type ObservabilityConfig

type ObservabilityConfig struct {
	Enabled bool
	Tracer  trace.Tracer
}

type OpenAIDecider added in v0.2.31

type OpenAIDecider struct {
	Client *openai.Client
}

func (OpenAIDecider) Decide added in v0.2.31

type PermissionAction

type PermissionAction string
const (
	PermissionAllow PermissionAction = "allow"
	PermissionDeny  PermissionAction = "deny"
	PermissionAuto  PermissionAction = "auto"
)

type PermissionBucket

type PermissionBucket struct {
	Name  string
	Rules []PermissionRule
}

type PermissionReview

type PermissionReview struct {
	Outcome   permissionReviewOutcome
	Rationale string
}

func (PermissionReview) CodeModeCall

func (r PermissionReview) CodeModeCall(e *SessionEntry) (CodeModeCall, bool)

type PermissionRule

type PermissionRule struct {
	Pattern  string
	Action   PermissionAction
	Reviewer string
	Except   []string
	// contains filtered or unexported fields
}

type PermissionSet

type PermissionSet struct {
	Buckets []PermissionBucket
	Sudo    bool
	Easy    bool
	// contains filtered or unexported fields
}

func (PermissionSet) Enabled

func (ps PermissionSet) Enabled(permission, subject string) bool

func (PermissionSet) Evaluate

func (ps PermissionSet) Evaluate(permission, subject string) (action PermissionAction, matched bool)

func (*PermissionSet) Set

func (ps *PermissionSet) Set(permission, pattern string, action PermissionAction, except ...string) error

type PromptInput

type PromptInput struct {
	ID                  string
	TurnID              string
	Role                PromptInputRole
	Texts               []string
	ExpandShellCommands bool `json:",omitempty"`
	Header              string
	Attachments         []Attachment
	DirectSkill         *PromptInputDirectSkill
	Agent               string
	Responses           chan<- ChatResponse `json:"-"`
}

type PromptInputDirectSkill

type PromptInputDirectSkill struct {
	Name           string `json:"name"`
	Arguments      string `json:"arguments,omitempty"`
	PlainIfUnknown bool   `json:"plainIfUnknown,omitempty"`
}

type PromptInputRole

type PromptInputRole string
const (
	PromptInputRoleUser      PromptInputRole = "user"
	PromptInputRoleDeveloper PromptInputRole = "developer"
)

type PromptShellCommandExpansion

type PromptShellCommandExpansion struct {
	PrimaryPrompts  bool
	SubagentPrompts bool
	SkillPrompts    bool
}

type ProviderDiagnostic

type ProviderDiagnostic struct {
	Provider       string            `json:"provider"`
	Model          string            `json:"model"`
	Phase          string            `json:"phase"`
	HTTPStatus     int               `json:"http_status,omitempty"`
	ResponseStatus string            `json:"response_status,omitempty"`
	Code           string            `json:"code,omitempty"`
	Type           string            `json:"type,omitempty"`
	Message        string            `json:"message,omitempty"`
	Attempt        int               `json:"attempt,omitempty"`
	RetryAfter     string            `json:"retry_after,omitempty"`
	ResponseID     string            `json:"response_id,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
}

type ProviderOrigin

type ProviderOrigin struct {
	Provider                           string
	Model                              string
	CompactThreshold                   int64
	PromptCacheMarkersRelativePosition *int
}

type PublicProgress

type PublicProgress struct {
	ID          string              `json:"id"`
	ParentID    string              `json:"parent_id,omitempty"`
	Kind        PublicProgressKind  `json:"kind"`
	State       PublicProgressState `json:"state"`
	Text        string              `json:"text,omitempty"`
	Agent       string              `json:"agent,omitempty"`
	Model       string              `json:"model,omitempty"`
	SubagentKey string              `json:"subagent_key,omitempty"`
}

func PublicProgressFromTrace

func PublicProgressFromTrace(traces []json.RawMessage) []PublicProgress

type PublicProgressKind

type PublicProgressKind string
const (
	PublicProgressText       PublicProgressKind = "text"
	PublicProgressThinking   PublicProgressKind = "thinking"
	PublicProgressTool       PublicProgressKind = "tool"
	PublicProgressDelegation PublicProgressKind = "delegation"
)

type PublicProgressState

type PublicProgressState string
const (
	PublicProgressWorking    PublicProgressState = "working"
	PublicProgressReview     PublicProgressState = "review"
	PublicProgressCompleted  PublicProgressState = "completed"
	PublicProgressBlocked    PublicProgressState = "blocked"
	PublicProgressFailed     PublicProgressState = "failed"
	PublicProgressStopped    PublicProgressState = "stopped"
	PublicProgressBackground PublicProgressState = "background"
)

type ReplayAttribution

type ReplayAttribution struct {
	Start           int     `json:"start"`
	End             int     `json:"end"`
	Agent           string  `json:"agent,omitempty"`
	Model           string  `json:"model,omitempty"`
	ReasoningEffort *string `json:"reasoning_effort,omitempty"`
}

type ReplayDecodeError

type ReplayDecodeError struct {
	EntryIndex int
	ItemIndex  int
	Kind       string
	Cause      error
}

func (*ReplayDecodeError) Error

func (e *ReplayDecodeError) Error() string

func (*ReplayDecodeError) Unwrap

func (e *ReplayDecodeError) Unwrap() error

type RetainedFiles added in v0.2.59

type RetainedFiles struct {
	ResultID string
}

type Runtime

type Runtime = looper

func NewWithModelResolver

func NewWithModelResolver(
	resolver ModelResolver,
	configInput *Config,
	root *os.Root,
	agents Agents,
	skills Skills,
	defaultAgent string,
) (*Runtime, error)

type SessionEntry

type SessionEntry struct {
	Version           int                 `json:"version"`
	Type              string              `json:"type"`
	Timestamp         time.Time           `json:"timestamp"`
	TurnID            string              `json:"turn_id,omitempty"`
	ResponseID        string              `json:"response_id,omitempty"`
	Model             string              `json:"model,omitempty"`
	Agent             string              `json:"agent,omitempty"`
	ReasoningEffort   *string             `json:"reasoning_effort,omitempty"`
	ReplayAttribution []ReplayAttribution `json:"replay_attribution,omitempty"`
	TokenUsage        *TokenUsage         `json:"token_usage,omitempty"`
	ReplayInput       []json.RawMessage   `json:"replay_input,omitempty"`
	OutputTrace       []json.RawMessage   `json:"output_trace,omitempty"`
}

func (*SessionEntry) AttributionAt

func (e *SessionEntry) AttributionAt(index int) ReplayAttribution

func (*SessionEntry) PermissionReviewDecision

func (e *SessionEntry) PermissionReviewDecision() PermissionReview

type Skill

type Skill struct {
	Name          string
	Description   string
	License       string
	Compatibility string
	Metadata      map[string]any
	Location      string
	Content       string
}

type SkillLoadResult

type SkillLoadResult struct {
	Skills Skills
	Errors []error
}

func LoadSkills

func LoadSkills(fsys fs.FS, root string) SkillLoadResult

type Skills

type Skills struct {
	Root  string
	Items map[string]Skill
	// contains filtered or unexported fields
}

func (Skills) Available

func (s Skills) Available(agent *Agent) []Skill

func (Skills) FindAvailable

func (s Skills) FindAvailable(query string, agent *Agent) string

type SteerDrain

type SteerDrain interface {
	Drain(ctx context.Context, responseID string, phase TurnPhase, applied []string) ([]PromptInput, error)
}

type SubagentWrite

type SubagentWrite struct {
	Key                      ChildKey
	CallKey                  string
	Agent, Delegator, Prompt string
	Mode                     ContinueMode
	Model                    string
	Tools                    []string
}

type TokenUsage

type TokenUsage struct {
	PromptTokens              int64 `json:"prompt_tokens,omitempty"`
	CompletionTokens          int64 `json:"completion_tokens,omitempty"`
	TotalTokens               int64 `json:"total_tokens,omitempty"`
	PromptCacheReadTokens     int64 `json:"prompt_cache_read_tokens,omitempty"`
	PromptCacheWriteTokens    int64 `json:"prompt_cache_write_tokens,omitempty"`
	CompletionReasoningTokens int64 `json:"completion_reasoning_tokens,omitempty"`
}

type Tool

type Tool struct {
	Name               string
	Description        string
	Parameters         map[string]any
	Permission         string
	VisibilitySubjects []string
	Subjects           func(json.RawMessage) ([]string, error)
	Call               func(context.Context, json.RawMessage, chan<- ChatResponse) (ToolResult, error)
	Resumable          bool
	TurnBound          bool
}

type ToolResult

type ToolResult struct {
	Output      string
	Attachments []Attachment
	Data        any
}

func TextToolResult

func TextToolResult(output string) ToolResult

func ToolCallResult added in v0.2.59

func ToolCallResult(name string, result ToolResult, err error) ToolResult

type TurnItems

type TurnItems struct {
	List  TurnList
	From  int
	Items []json.RawMessage
}

type TurnList

type TurnList string
const (
	TurnReplayInput TurnList = "replay_input"
	TurnOutputTrace TurnList = "output_trace"
	TurnTrace       TurnList = "trace"
)

type TurnPhase

type TurnPhase int
const (
	TurnPhaseUnclassified TurnPhase = iota
	TurnPhaseToolLoop
	TurnPhaseFinalAnswer
)

type TypeSafeDecider added in v0.2.31

type TypeSafeDecider struct {
	HTTPClient *http.Client
	APIKey     string
	BaseURL    string
}

func (TypeSafeDecider) Decide added in v0.2.31

Jump to

Keyboard shortcuts

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