agent

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent is the serial coordinator for autonomous TUI agent requests and the presentation of their transcripts. Each request owns the provider/model selected when it was submitted, but at most one adapter is ever running. The queue records transcripts and outcomes for presentation; it never reads or writes task data itself.

Go port of Ruby's lib/tui/agent_queue.rb and lib/tui/agent_activity.rb. Unlike Ruby's single-threaded original, every operation takes a mutex, so the FIFO order Marcus relies on holds even when submissions arrive from a background reader.

Index

Constants

View Source
const (
	// MaxPending is how many requests may wait behind the running one.
	MaxPending = 100
	// HistoryLimit is how many finished requests are retained.
	HistoryLimit = 50
)

Variables

View Source
var Glyphs = map[Status]string{
	Queued:    "○",
	Running:   "⠸",
	Succeeded: "✓",
	Failed:    "✗",
	Cancelled: "–",
}

Glyphs is the status marker shown against each request.

View Source
var Slots = map[Status]theme.Slot{
	Queued:    "muted",
	Running:   "accent",
	Succeeded: "accent",
	Failed:    "error",
	Cancelled: "warning",
}

Slots is the theme slot each status paints with.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Available re-checks the provider at start time.
	Available() bool
	Start(prompt, model string) error
	// Pump drains one readable chunk; done reports that the process finished.
	Pump() (done bool, err error)
	Cancel() error
	Output() string
	Success() bool
	// ExitStatus reports the process exit code, if one is known.
	ExitStatus() (int, bool)
	ProcessStatus() ProcessStatus
}

Adapter is one live agent process. Only one is ever running per queue.

type Content

type Content struct {
	Title        string
	Lines        []string
	FilterGroups []int
}

Content is the rendered agent-activity modal body. FilterGroups is parallel to Lines and names the request each line belongs to, so filtering a line keeps its whole request block together.

func Activity

func Activity(th *theme.Theme, requests []Snapshot, now float64, width int) Content

Activity renders AgentQueue snapshots. It deliberately shows the exact captured transcript rather than interpreting agent output or task mutations.

Go port of Ruby's lib/tui/agent_activity.rb.

type Entry

type Entry interface {
	Provider() string
	Model() string
	// UILabel is the short "provider:model" form the activity view shows.
	UILabel() string
}

Entry names the provider/model a request was submitted with. The LLM layer supplies the real implementation; the queue only reads it.

type Event

type Event struct {
	Type    EventType
	Request Snapshot
}

Event reports a queue transition. Type is empty when nothing happened.

func (Event) Occurred

func (e Event) Occurred() bool

Occurred reports whether the call produced a transition.

type EventType

type EventType string

EventType distinguishes a start from a completion.

const (
	Started  EventType = "started"
	Finished EventType = "finished"
)

type Options

type Options struct {
	// Factory builds a fresh adapter for an entry, with the current system
	// context, only when a request actually starts.
	Factory func(Entry) (Adapter, error)
	// Availability is a lightweight probe run at enqueue so an unavailable
	// provider is rejected immediately without building the (context-bearing,
	// possibly failing) adapter. A nil probe means "assume available";
	// StartNext's re-check is the backstop either way.
	Availability func(Entry) bool
	// Clock returns monotonic seconds. Defaults to process-monotonic time.
	Clock        func() float64
	MaxPending   int
	HistoryLimit int
}

Options configures a queue.

type ProcessStatus

type ProcessStatus struct {
	// Present is false when the adapter never produced a process status.
	Present    bool
	Exited     bool
	ExitStatus int
	Signaled   bool
	Signal     int
}

ProcessStatus describes how an adapter's process ended.

type Queue

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

Queue is the serial request coordinator.

func NewQueue

func NewQueue(opts Options) (*Queue, error)

NewQueue builds a queue. Factory must be non-nil.

func (*Queue) Active

func (q *Queue) Active() bool

func (*Queue) ActiveOutput

func (q *Queue) ActiveOutput() string

ActiveOutput is the live transcript of the running request.

func (*Queue) ActiveRequest

func (q *Queue) ActiveRequest() (Snapshot, bool)

ActiveRequest snapshots the running request, if any.

func (*Queue) Any

func (q *Queue) Any() bool

Any reports whether any request is retained.

func (*Queue) CancelActive

func (q *Queue) CancelActive() Event

CancelActive stops the running request, preserving its partial output.

func (*Queue) CancelPending

func (q *Queue) CancelPending() []Snapshot

CancelPending discards everything waiting without touching the live adapter.

func (*Queue) Enqueue

func (q *Queue) Enqueue(prompt string, entry Entry) Submission

Enqueue submits a prompt. A full queue or an unavailable provider is a rejection, and no request is recorded.

func (*Queue) LatestFinished

func (q *Queue) LatestFinished() (Snapshot, bool)

LatestFinished is the most recently completed request.

func (*Queue) Now

func (q *Queue) Now() float64

Now samples the queue's own monotonic clock. Activity rendering must use the same clock domain as queuedAt/startedAt.

func (*Queue) Pending

func (q *Queue) Pending() bool

func (*Queue) PendingCount

func (q *Queue) PendingCount() int

func (*Queue) Pump

func (q *Queue) Pump() Event

Pump drains one readable chunk. A finished adapter is recorded, but the next request is deliberately not started here: the application first reloads task state, then advances the queue, to preserve a visible checkpoint between runs.

func (*Queue) Requests

func (q *Queue) Requests() []Snapshot

Requests snapshots every retained request, oldest first.

func (*Queue) Shutdown

func (q *Queue) Shutdown() []Snapshot

Shutdown is the exit path: stop everything without advancing to another request.

func (*Queue) StartNext

func (q *Queue) StartNext() Event

StartNext attempts exactly one queued request. A start-time availability/spawn failure is a finished event so the caller can report it and call again; a successful start returns Started and owns the single live adapter.

func (*Queue) SubmittedCount

func (q *Queue) SubmittedCount() int

SubmittedCount is how many requests have ever been accepted.

func (*Queue) Work

func (q *Queue) Work() bool

Work reports whether anything is running or waiting.

type SimpleEntry

type SimpleEntry struct {
	ProviderName string
	ModelName    string
	Label        string
}

SimpleEntry is a provider/model pair with no label mapping — enough for callers and tests that do not need the LLM registry's display names.

func (SimpleEntry) Model

func (e SimpleEntry) Model() string

func (SimpleEntry) Provider

func (e SimpleEntry) Provider() string

func (SimpleEntry) UILabel

func (e SimpleEntry) UILabel() string

type Snapshot

type Snapshot struct {
	ID         int
	Prompt     string
	Entry      Entry
	Status     Status
	QueuedAt   float64
	StartedAt  *float64
	FinishedAt *float64
	Output     string
	ExitStatus *int
	Error      string
}

Snapshot is an immutable view of one request.

func (Snapshot) Elapsed

func (s Snapshot) Elapsed(now float64) float64

Elapsed is how long the request has been (or was) running, in seconds.

func (Snapshot) Finished

func (s Snapshot) Finished() bool

Finished reports whether the request reached a terminal status.

type Status

type Status string

Status is a request's lifecycle state.

const (
	Queued    Status = "queued"
	Running   Status = "running"
	Succeeded Status = "succeeded"
	Failed    Status = "failed"
	Cancelled Status = "cancelled"
)

func (Status) Finished

func (s Status) Finished() bool

Finished reports whether a status is terminal.

type Submission

type Submission struct {
	Request *Snapshot
	Error   string
}

Submission is the outcome of an enqueue attempt.

func (Submission) Accepted

func (s Submission) Accepted() bool

Accepted reports whether the request joined the queue.

Jump to

Keyboard shortcuts

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