Documentation
¶
Index ¶
- Variables
- func SanitizeInput(input string) (string, error)
- type ContentRenderer
- type IOHandler
- type JSONHandler
- func (h *JSONHandler) HandleTool(ctx context.Context, call domain.ToolCall) (domain.ToolResult, error)
- func (h *JSONHandler) Input(ctx context.Context) (string, error)
- func (h *JSONHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)
- func (h *JSONHandler) SystemOutput(ctx context.Context, msg string) error
- type Runner
- type SignalManager
- type TextHandler
- func (h *TextHandler) HandleTool(ctx context.Context, call domain.ToolCall) (domain.ToolResult, error)
- func (h *TextHandler) Input(ctx context.Context) (string, error)
- func (h *TextHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)
- func (h *TextHandler) SystemOutput(ctx context.Context, msg string) error
- type ToolInterceptor
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultMaxInputSize is 4KB (conservative default) DefaultMaxInputSize = 4096 // EnvMaxInputSize is the environment variable to override the default EnvMaxInputSize = "TRELLIS_MAX_INPUT_SIZE" )
var ( ErrInputTooLarge = errors.New("input exceeds maximum allowed size") ErrInvalidUTF8 = errors.New("input contains invalid UTF-8 sequences") )
Functions ¶
func SanitizeInput ¶ added in v0.5.2
SanitizeInput cleans user input by enforcing size limits, validating UTF-8, and stripping dangerous control characters.
Types ¶
type ContentRenderer ¶
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)
// SystemOutput presents a meta-message to the user (e.g. system logs, status updates).
// This is distinct from content rendering.
SystemOutput(ctx context.Context, msg string) 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 {
Writer io.Writer
Encoder *json.Encoder
Registry *registry.Registry
// contains filtered or unexported fields
}
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. It starts a background goroutine to read from r.
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.
func (*JSONHandler) Output ¶
func (h *JSONHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)
func (*JSONHandler) SystemOutput ¶ added in v0.5.0
func (h *JSONHandler) SystemOutput(ctx context.Context, msg string) error
type Runner ¶
type Runner struct {
// Handler is the strategy for IO. If nil, it falls back to legacy fields.
Handler IOHandler
// Interceptor is a middleware for tool execution policy.
// If nil, defaults to AutoApprove (Phase 1 behavior).
Interceptor ToolInterceptor
// Logger is used for internal debug logging.
// If nil, a no-op logger is used.
Logger *slog.Logger
// 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).
type SignalManager ¶ added in v0.5.2
type SignalManager struct {
// contains filtered or unexported fields
}
SignalManager handles the complexity of OS signals, context cancellation, and platform-specific race conditions (e.g. Windows Stdin EOF vs Interrupt).
func NewSignalManager ¶ added in v0.5.2
func NewSignalManager() *SignalManager
NewSignalManager creates a new manager and immediately starts listening for signals.
func (*SignalManager) CheckRace ¶ added in v0.5.2
func (sm *SignalManager) CheckRace()
CheckRace waits briefly to see if a context cancellation follows an error. This is specifically to mitigate a race condition on Windows/PowerShell where Ctrl+C causes an EOF or Input Error slightly before the signal context is cancelled.
func (*SignalManager) Context ¶ added in v0.5.2
func (sm *SignalManager) Context() context.Context
Context returns the current signal context.
func (*SignalManager) Reset ¶ added in v0.5.2
func (sm *SignalManager) Reset()
Reset re-arms the signal listener. Should be called after a signal has been successfully handled/intercepted to allow capturing subsequent signals.
func (*SignalManager) Stop ¶ added in v0.5.2
func (sm *SignalManager) Stop()
Stop permanently stops the signal listener.
type TextHandler ¶
type TextHandler struct {
Reader *bufio.Reader
Writer io.Writer
Renderer ContentRenderer
Registry *registry.Registry
// contains filtered or unexported fields
}
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) Output ¶
func (h *TextHandler) Output(ctx context.Context, actions []domain.ActionRequest) (bool, error)
func (*TextHandler) SystemOutput ¶ added in v0.5.0
func (h *TextHandler) SystemOutput(ctx context.Context, msg string) error
type ToolInterceptor ¶ added in v0.5.0
type ToolInterceptor func(ctx context.Context, call domain.ToolCall) (bool, domain.ToolResult, error)
ToolInterceptor is a middleware that can intercept, modify, or block a tool call. It returns true if execution should proceed, or false to block it. If blocked, it should return a ToolResult describing the denial (typically an error).
func AutoApproveMiddleware ¶ added in v0.5.0
func AutoApproveMiddleware() ToolInterceptor
AutoApproveMiddleware allows everything.
func ConfirmationMiddleware ¶ added in v0.5.0
func ConfirmationMiddleware(handler IOHandler) ToolInterceptor
ConfirmationMiddleware prompts the user via the provided Handler before allowing execution. It is "aware" of the IOHandler to use its Input/Output methods, but keeps the policy logic separate.
Note: This leverages the IOHandler.SystemOutput capability to send meta-messages. This allows the prompt ("Allow execution?") to be distinct from the flow content.
func MultiInterceptor ¶ added in v0.5.0
func MultiInterceptor(interceptors ...ToolInterceptor) ToolInterceptor
MultiInterceptor chains multiple interceptors.