screentracker

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessageValidationWhitespace = xerrors.New("message must be trimmed of leading and trailing whitespace")
	ErrMessageValidationEmpty      = xerrors.New("message must not be empty")
	ErrMessageValidationChanging   = xerrors.New("message can only be sent when the agent is waiting for user input")
)

Functions

This section is empty.

Types

type AgentIO

type AgentIO interface {
	Write(data []byte) (int, error)
	ReadScreen() string
}

type AgentState added in v0.12.0

type AgentState struct {
	Version           int                   `json:"version"`
	Messages          []ConversationMessage `json:"messages"`
	InitialPrompt     string                `json:"initial_prompt"`
	InitialPromptSent bool                  `json:"initial_prompt_sent"`
}

type Conversation

type Conversation interface {
	Messages() []ConversationMessage
	Send(...MessagePart) error
	Start(context.Context)
	Status() ConversationStatus
	Text() string
	SaveState() error
}

Conversation represents a conversation between a user and an agent. It is intended as the primary interface for interacting with a session. Implementations must support the following capabilities:

  • Fetching all messages between the user and agent,
  • Sending a message to the agent,
  • Starting a background loop to update the conversation state, if required,
  • Fetching the status of the conversation,
  • Returning a textual representation of the conversation "screen" (used for notifying subscribers of updates to the conversation).

type ConversationMessage

type ConversationMessage struct {
	Id      int              `json:"id"`
	Message string           `json:"message"`
	Role    ConversationRole `json:"role"`
	Time    time.Time        `json:"time"`
}

type ConversationRole

type ConversationRole string
const (
	ConversationRoleUser  ConversationRole = "user"
	ConversationRoleAgent ConversationRole = "agent"
)

func (ConversationRole) Schema

func (c ConversationRole) Schema(r huma.Registry) *huma.Schema

type ConversationStatus

type ConversationStatus string
const (
	ConversationStatusChanging     ConversationStatus = "changing"
	ConversationStatusStable       ConversationStatus = "stable"
	ConversationStatusInitializing ConversationStatus = "initializing"
)

type Emitter added in v0.12.0

type Emitter interface {
	EmitMessages([]ConversationMessage)
	EmitStatus(ConversationStatus)
	EmitScreen(string)
	EmitError(message string, level ErrorLevel)
}

Emitter receives conversation state updates.

type ErrorLevel added in v0.12.0

type ErrorLevel string
const (
	ErrorLevelWarning ErrorLevel = "warning"
	ErrorLevelError   ErrorLevel = "error"
)

func (ErrorLevel) Schema added in v0.12.0

func (e ErrorLevel) Schema(r huma.Registry) *huma.Schema

type LoadStateStatus added in v0.12.0

type LoadStateStatus int

LoadStateStatus represents the state of loading persisted conversation state.

const (
	// LoadStatePending indicates state loading has not been attempted yet.
	LoadStatePending LoadStateStatus = iota
	// LoadStateSucceeded indicates state was successfully loaded.
	LoadStateSucceeded
	// LoadStateFailed indicates state loading was attempted but failed.
	LoadStateFailed
)

type MessagePart

type MessagePart interface {
	Do(writer AgentIO) error
	String() string
}

type MessagePartText

type MessagePartText struct {
	Content string
	Alias   string
	Hidden  bool
}

func (MessagePartText) Do

func (p MessagePartText) Do(writer AgentIO) error

func (MessagePartText) String

func (p MessagePartText) String() string

type PTYConversation added in v0.12.0

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

PTYConversation is a conversation that uses a pseudo-terminal (PTY) for communication. It uses a combination of polling and diffs to detect changes in the screen.

func NewPTY added in v0.12.0

func NewPTY(ctx context.Context, cfg PTYConversationConfig, emitter Emitter) *PTYConversation

func (*PTYConversation) Messages added in v0.12.0

func (c *PTYConversation) Messages() []ConversationMessage

func (*PTYConversation) SaveState added in v0.12.0

func (c *PTYConversation) SaveState() error

func (*PTYConversation) Send added in v0.12.0

func (c *PTYConversation) Send(messageParts ...MessagePart) error

func (*PTYConversation) Start added in v0.12.0

func (c *PTYConversation) Start(ctx context.Context)

func (*PTYConversation) Status added in v0.12.0

func (c *PTYConversation) Status() ConversationStatus

func (*PTYConversation) Text added in v0.12.0

func (c *PTYConversation) Text() string

type PTYConversationConfig added in v0.12.0

type PTYConversationConfig struct {
	AgentType msgfmt.AgentType
	AgentIO   AgentIO
	// Clock provides time operations for the conversation
	Clock quartz.Clock
	// How often to take a snapshot for the stability check
	SnapshotInterval time.Duration
	// How long the screen should not change to be considered stable
	ScreenStabilityLength time.Duration
	// Function to format the messages received from the agent
	// userInput is the last user message
	FormatMessage func(message string, userInput string) string
	// ReadyForInitialPrompt detects whether the agent has initialized and is ready to accept the initial prompt
	ReadyForInitialPrompt func(message string) bool
	// FormatToolCall removes the coder report_task tool call from the agent message and also returns the array of removed tool calls
	FormatToolCall func(message string) (string, []string)
	// InitialPrompt is the initial prompt to send to the agent once ready
	InitialPrompt          []MessagePart
	Logger                 *slog.Logger
	StatePersistenceConfig StatePersistenceConfig
}

PTYConversationConfig is the configuration for a PTYConversation.

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer is a generic circular buffer that can store items of any type

func NewRingBuffer

func NewRingBuffer[T any](size int) *RingBuffer[T]

NewRingBuffer creates a new ring buffer with the specified size

func (*RingBuffer[T]) Add

func (r *RingBuffer[T]) Add(item T)

Add adds an item to the ring buffer

func (*RingBuffer[T]) Capacity

func (b *RingBuffer[T]) Capacity() int

Capacity returns the capacity of the ring buffer

func (*RingBuffer[T]) GetAll

func (b *RingBuffer[T]) GetAll() []T

GetAll returns all items in the buffer, oldest first

type StatePersistenceConfig added in v0.12.0

type StatePersistenceConfig struct {
	StateFile string
	LoadState bool
	SaveState bool
}

Jump to

Keyboard shortcuts

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