Help us shape the future of Go! Take the 2026 Go Developer Survey

present

package
v0.45.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

Message Presenter

present.Presenter may add bounded text before and after a user message. Harness gives it cloned input blocks, validates and clones the returned frame, and journals that frame once so replay and restore show the model the same message. Presenters must handle a nil principal and should be deterministic in their input. Machine-originated messages bypass the presenter.

Register one with rig.WithMessagePresenter. Present(ctx, in) receives the session and loop IDs, agent name, command kind, optional principal and metadata, and cloned original blocks. Return present.Frame{Prefix, Suffix} containing at most eight nonempty text blocks and 8192 UTF-8 bytes in total. The user blocks remain between the two frame parts. A presenter error, panic, or invalid frame returns a typed *present.Error and sends no message. The 5s context bounds cooperative implementations only; Harness cannot stop a presenter that ignores context.

Documentation

Overview

Package present defines the Message Presenter contract. A product hook may prepend and append text to a user message, but may not edit the user's blocks. The session journals the rendering so restore and replay never re-render it. Machine-originated input is never presented.

A presenter should be deterministic in its Input. A command redelivered before its durable application prefix may be presented again.

Index

Constants

View Source
const (
	// MaxFrameBlocks bounds Prefix and Suffix combined.
	MaxFrameBlocks = 8
	// MaxFrameTextBytes bounds their summed UTF-8 text bytes.
	MaxFrameTextBytes = 8192
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Kind  ErrorKind
	Cause error
}

Error is a typed presentation failure. Error deliberately prints only Kind: product errors may name a person and must not be logged by harness.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind string

ErrorKind classifies a presentation failure.

const (
	ErrorPresenterFailed ErrorKind = "presenter_failed"
	ErrorFrameInvalid    ErrorKind = "frame_invalid"
)

type Frame

type Frame struct {
	Prefix []content.Block
	Suffix []content.Block
}

Frame is the text placed before and after the user's own blocks.

func Run

func Run(ctx context.Context, p Presenter, in Input) (frame Frame, err error)

Run invokes a presenter with a defensive copy and returns a validated, separately cloned frame. A presenter error or panic is ErrorPresenterFailed.

func (Frame) Empty

func (f Frame) Empty() bool

Empty reports whether this frame adds any blocks.

func (Frame) Validate

func (f Frame) Validate() error

Validate permits only nonempty text blocks and applies both frame limits.

type Input

type Input struct {
	SessionID uuid.UUID
	LoopID    uuid.UUID
	AgentName identity.AgentName
	Kind      runtimecommand.Kind
	Principal *sessionwire.Principal
	Metadata  sessionwire.MessageMetadata
	Blocks    []content.Block
}

Input is the read-only context given to a presenter. Principal and Metadata are nil when absent. Blocks is a clone of the user's original blocks.

type Presenter

type Presenter interface {
	Present(context.Context, Input) (Frame, error)
}

Presenter frames one user message.

Jump to

Keyboard shortcuts

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