runner

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

Run executes the agent for a single turn, wrapping the response with a Langfuse trace when a tracer is present, enforcing todo-completion guards, and sending token-usage updates to the handler when done.

Types

type ApprovalState

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

ApprovalState manages whether tool calls require interactive user approval.

func NewApprovalState

func NewApprovalState(workpath string, autoApprove bool) *ApprovalState

NewApprovalState creates a new ApprovalState with the given workpath.

func (*ApprovalState) GetMode

func (s *ApprovalState) GetMode() handler.ApprovalMode

GetMode returns the current approval mode.

func (*ApprovalState) NewTeammateApprovalFunc

func (s *ApprovalState) NewTeammateApprovalFunc(workerName, workerColor string) func(ctx context.Context, toolName, toolArgs string) (bool, error)

NewTeammateApprovalFunc creates an approval function for a teammate that includes the worker identity in the TUI approval prompt.

func (*ApprovalState) RequestApproval

func (s *ApprovalState) RequestApproval(ctx context.Context, toolName, toolArgs string) (bool, error)

RequestApproval is the agent.ApprovalFunc implementation. It returns true immediately for read-only or obviously safe commands. For everything else it sends a TUI prompt and waits for the user's answer.

func (*ApprovalState) SetHandler

func (s *ApprovalState) SetHandler(h handler.AgentEventHandler)

SetHandler stores the handler used to send approval-request messages.

func (*ApprovalState) SetMode

func (s *ApprovalState) SetMode(mode handler.ApprovalMode)

SetMode sets the approval mode (used for external mode changes).

func (*ApprovalState) SetSessionApproval

func (s *ApprovalState) SetSessionApproval(enabled bool)

SetSessionApproval sets the approval mode based on the boolean value. This is kept for backward compatibility with the channel-based mode sync.

func (*ApprovalState) SetWorkpath

func (s *ApprovalState) SetWorkpath(path string)

SetWorkpath sets the current working directory (called on environment switch).

type Event

type Event struct {
	Type       EventType
	Text       string
	ToolCall   *ToolCallEvent
	ToolResult *ToolResultEvent
	Error      error
	Meta       map[string]any
}

Event is the unit of data emitted by the agent loop.

type EventBus

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

EventBus is a channel-based event bus for streaming agent loop events to the TUI and other consumers.

func NewEventBus

func NewEventBus(bufferSize int) *EventBus

NewEventBus creates an event bus with the given channel buffer size.

func (*EventBus) Close

func (eb *EventBus) Close()

Close shuts down the event bus. Safe to call multiple times.

func (*EventBus) Done

func (eb *EventBus) Done() <-chan struct{}

Done returns a channel that is closed when the event bus is shut down.

func (*EventBus) Emit

func (eb *EventBus) Emit(event Event)

Emit sends an event to the bus. Non-blocking: drops the event if the channel is full or the bus is closed, and logs a warning.

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe() <-chan Event

Subscribe returns the read-only event channel.

type EventType

type EventType int

EventType categorises events flowing through the EventBus.

const (
	EventAssistantText EventType = iota
	EventAssistantDone
	EventToolCall
	EventToolResult
	EventError
	EventBudgetWarning
	EventCompaction
	EventWorkerStatus
)

type ToolCallEvent

type ToolCallEvent struct {
	Name string
	Args string
}

ToolCallEvent describes a tool invocation.

type ToolResultEvent

type ToolResultEvent struct {
	Name   string
	Output string
	Err    error
}

ToolResultEvent describes a tool's result.

Jump to

Keyboard shortcuts

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