runner

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentRenderer

type ContentRenderer func(string) (string, error)

ContentRenderer is a function that transforms the content before outputting it. This allows for TUI rendering (markdown to ANSI) without coupling the core package.

type IOHandler

type IOHandler interface {
	// Output presents the actions to the user.
	// Returns true if the output requires user input (e.g. asking a question),
	// or if the handler expects to read input after this.
	Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)

	// Input reads a response from the user.
	Input(ctx context.Context) (string, error)

	// HandleTool executes a side-effect requested by the engine.
	// In a text/CLI context, this might just log the request or ask for confirmation.
	HandleTool(ctx context.Context, call domain.ToolCall) (domain.ToolResult, error)
}

IOHandler defines the strategy for interacting with the user. This allows switching between Text (CLI/TUI) and JSON (Structured) modes.

type JSONHandler

type JSONHandler struct {
	Reader  *bufio.Reader
	Writer  io.Writer
	Encoder *json.Encoder
	Decoder *json.Decoder
}

JSONHandler implements the IOHandler interface for structured JSON-Lines communication.

func NewJSONHandler

func NewJSONHandler(r io.Reader, w io.Writer) *JSONHandler

NewJSONHandler creates a handler for JSON IO.

func (*JSONHandler) HandleTool added in v0.4.0

func (h *JSONHandler) HandleTool(ctx context.Context, call domain.ToolCall) (domain.ToolResult, error)

HandleTool for JSONHandler emits the tool call as JSON. In a real headless/JSON scenario, the Host should intercept this ActionRequest in the 'Output' phase and perform the action, or the Runner should handle this differently. For now, to satisfy the interface, we log it or return a mock if needed. Ideally, the JSON Runner shouldn't "execute" tools, it should just "pass through" the request to the caller. But the Runner loop calls this during StatusWaitingForTool.

func (*JSONHandler) Input

func (h *JSONHandler) Input(ctx context.Context) (string, error)

func (*JSONHandler) Output

func (h *JSONHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)

type Runner

type Runner struct {
	// Handler is the strategy for IO. If nil, it falls back to legacy fields.
	Handler IOHandler

	// Deprecated: Use Handler instead. These are kept for backward compatibility.
	Input    io.Reader
	Output   io.Writer
	Headless bool
	Renderer ContentRenderer
}

Runner handles the execution loop of the Trellis engine using provided IO. This allows for easy testing and integration with different frontends (CLI, TUI, etc). Runner handles the execution loop of the Trellis engine using provided IO. It uses an IOHandler strategy to abstract the interaction mode (Text vs JSON).

func NewRunner

func NewRunner() *Runner

NewRunner creates a new Runner with default Stdin/Stdout.

func (*Runner) Run

func (r *Runner) Run(engine *trellis.Engine) error

Run executes the engine loop until termination.

type TextHandler

type TextHandler struct {
	Reader   *bufio.Reader
	Writer   io.Writer
	Renderer ContentRenderer
}

TextHandler implements the standard text-based interface.

func NewTextHandler

func NewTextHandler(r io.Reader, w io.Writer) *TextHandler

NewTextHandler creates a handler for standard text IO.

func (*TextHandler) HandleTool added in v0.4.0

func (h *TextHandler) HandleTool(ctx context.Context, call domain.ToolCall) (domain.ToolResult, error)

HandleTool for TextHandler mocks the execution by printing to stdout.

func (*TextHandler) Input

func (h *TextHandler) Input(ctx context.Context) (string, error)

func (*TextHandler) Output

func (h *TextHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)

Jump to

Keyboard shortcuts

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